当前位置: 技术问答>linux和unix
关于linux内核代码编译,求赐教
来源: 互联网 发布时间:2017-05-20
本文导语: 看到一个intel的测试程序,程序如下,正常在linux下用gcc编译,总是提示很多错误,在网上搜了之后,发现和内核有关,需要写makefile文件,对这些不太明白,想请问怎么运行下边的程序,而且如果测试函数换成sin等,...
看到一个intel的测试程序,程序如下,正常在linux下用gcc编译,总是提示很多错误,在网上搜了之后,发现和内核有关,需要写makefile文件,对这些不太明白,想请问怎么运行下边的程序,而且如果测试函数换成sin等,这个程序怎么改?
#include
#include
#include
#include
#include
#include
void inline measured_function(volatile int *var)
{
(*var) = 1;
}
static int __init hello_start(void)
{
unsigned long flags;
uint64_t start, end;
int variable = 0;
unsigned cycles_low, cycles_high, cycles_low1, cycles_high1;
printk(KERN_INFO "Loading test module...n");
preempt_disable(); /*we disable preemption on our CPU*/
raw_local_irq_save(flags); /*we disable hard interrupts on our CPU*/
/*at this stage we exclusively own the CPU*/
asm volatile (
"RDTSCnt"
"mov %%edx, %0nt"
"mov %%eax, %1nt": "=r" (cycles_high), "=r" (cycles_low));
measured_function(&variable);
asm volatile (
"RDTSCnt"
"mov %%edx, %0nt"
"mov %%eax, %1nt": "=r" (cycles_high1), "=r" (cycles_low1));
raw_local_irq_restore(flags);
/*we enable hard interrupts on our CPU*/
preempt_enable();/*we enable preemption*/
start = ( ((uint64_t)cycles_high
#include
#include
#include
#include
#include
#include
void inline measured_function(volatile int *var)
{
(*var) = 1;
}
static int __init hello_start(void)
{
unsigned long flags;
uint64_t start, end;
int variable = 0;
unsigned cycles_low, cycles_high, cycles_low1, cycles_high1;
printk(KERN_INFO "Loading test module...n");
preempt_disable(); /*we disable preemption on our CPU*/
raw_local_irq_save(flags); /*we disable hard interrupts on our CPU*/
/*at this stage we exclusively own the CPU*/
asm volatile (
"RDTSCnt"
"mov %%edx, %0nt"
"mov %%eax, %1nt": "=r" (cycles_high), "=r" (cycles_low));
measured_function(&variable);
asm volatile (
"RDTSCnt"
"mov %%edx, %0nt"
"mov %%eax, %1nt": "=r" (cycles_high1), "=r" (cycles_low1));
raw_local_irq_restore(flags);
/*we enable hard interrupts on our CPU*/
preempt_enable();/*we enable preemption*/
start = ( ((uint64_t)cycles_high