cann't dump info to user file from kernel

2007-10-02 Thread kernel coder
hi,
  I'm trying to dump some information from dev.c to user space
file.Following is the code which i'm using to write to user spcae
file.I'm using 2.6.22.x86_64 kernel.


#define _write(f, buf, sz) (f->f_op->write(f, buf, sz, &f->f_pos))
#define WRITABLE(f) (f->f_op && f->f_op->write)

int write_to_file(char *logfile, char *buf,int size)
{
int ret = 0;
struct file *f=NULL;
mm_segment_t old_fs = get_fs();
set_fs(get_ds());
 f = filp_open(logfile, O_CREAT|O_APPEND,00600);
if(IS_ERR(f)){
DPRINT("Error %ld openeing %s\n",-PTR_ERR(f), logfile);
ret = -1;
} else {
if (WRITABLE(f))
_write(f, buf, size);
else {
DPRINT("%s does not have a write method\n",
logfile);
ret = -1;
}

if ((ret = filp_close(f,NULL)))
DPRINT("Error %d closing %s\n", -ret, logfile);
}
END_KMEM;

return ret;
}


I'm calling this function from netif_recieve_skb in dev.c

int netif_recieve_skb(struct sk_buff *skb){

-
write_to_file("/root/kernel_log","hello_world",12);
--

}

But whenever this function is called ,the kernel simply halts.Please
tell me what might be the reason.

I just want to dump some information to user spcace file from dev.c
.Is there some better way to do it.


thanks,
shahzad
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


profile code added to netif_receive_skb function

2007-11-25 Thread kernel coder
hi,

I have added some code to netif_receive_skb function.As linux kernel
is multhreaded , so there is no gaurantee than mine code is completely
executed without being disturbed by any other process .Timer interrupt
handler is an example of code which might interrupt execution of mine
code.

I just want to observe which processes are disturbing mine code .I
think i need to print EIP register values .How can i print cache
contents as well in linux kernel .Are there any tools available for
such purpose


thanks,
shahzad
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


increased number of cycles

2007-11-17 Thread kernel coder
hi,
I'm trying to add some code to netif_receive_skb function in
dev.c file . The cycles consumed by that code was around 16 cycles on
Dual Core Opetron machine.I'm working on that code for last 6 months
now and the consumed cycles have always been around 16 cycles .I don't
touch any other part of kernel .

But for last 4 days the consumed cycles have suddenly increased to
around 35 cycles . I'm using RDTSC instruction to profile the
code.There is no change in code and the kernel version is also the
same .I am assuming that there  must be something wrong with hardware.

Please guide me how can i figure out the root cause.What areas should
i look at to find out the reason for increased number of cycles.I
don't think that there is any issue in kernel because the kernel
version and code  is same. Can the the log messages during system
bootup help me to diagnose the problem


shahzad
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


tcp/ip stack question

2007-06-07 Thread kernel coder

hi,
  I am recieveing the packet on eth1 and want to send it through eth2.

I've written code in netif_recieve_skb function .This code changes the
mac header in sk_buff structure so that it can be send through other
interface card.But when i call ip_dev_find fucntion to get the second
interface structure ,NULL is returned.I checked the ip of second
ethernet card  and it was similar to one passed to ip_dev_find
fucntion,then why NULL is being returned?


Actually if i get the correct dev structure from ip_dev_find fucntion
then i'll assign that dev structure to current skbuff->dev  and call
dev_queue_xmit fucntion,so that it transmitted through second
interface card.Is mine approach correct?


shahzad
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


system call implementation for x86_64

2007-05-19 Thread kernel coder

hi,

I'm trying to implement a system call for x86_64. Mine processor is
dual core opetron.There is very little material on web for
implementing system calls for x86_64 processor for 2.6 series kernel.I
tried to implement a new system call by observing the existing
implementation but to no success.Following are files names and changes
made.

//
file-> include/asm-x86_64/unistd.h

#define __NR_newcall273
__SYSCALL(__NR_newcall, sys_newcall)

#define __NR_syscall_max __NR_newcall

//
file-> include/linux/syscalls.h

asmlinkage unsigned long sys_newcall(char __user *buf);

/
file--> fs/read_write.c

asmlinkage unsigned long sys_newcall(char __user * buf){

printk("new system call \n");
ret 0;
}

EXPORT_SYMBOL_GPL(sys_write)


Please let me know where i'm doing wrong .Following is program which
is calling mine system call


#include 
#include 
#include 
#include 

 long int ret;
  int num = 243;
 char  buffer=[20];

int main() {


 asm ("syscall;"
  : "=a" (ret)
  : "0" (num),
"D" (buffer),
 );
return ret;
}

When i call this ,nothing gets printed in file /var/log/messages.Am i
missing something ?

Actually i wana pass a pointer to kernel from user space.Later on data
will be copied to that memory location .i am thinking of using
copy_to_user for copying data.Buffer passed through system call will
be used by kernel function as circular ring.And portions of this ring
will get updated frequently even after system call has returned.

Is there any better way to do this?
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


AMD dual core opetron optimization

2007-04-30 Thread kernel coder

hi,

I'm doing trying to write some optimized code  for AMD dual core
opetron processor.But things are getting no where.I've installed
Fedora 5 with 2.6 series Linux kernel and 4 series GCC

Following are few lines of code which are consuming close to 100
cycles.Yes this is not the forum for such questions but i think people
on linux kernel and GCC are best to answer such type of questions.I'm
realy getting frustated and helpless ,that's why i've put question on
this forum.

/***/
/* these variables will be used for RDTSC instrucion */
uint64_t before, overhead, clocks;


/*ReadTsc funtion is given below */
before=ReadTsc();
before=ReadTsc();
before=ReadTsc();

overhead=ReadTsc()-before;

printf(" ReadTSC overerhead is %lu ",overhead);


unsigned int test;
unsigned long buffer [128];
buffer[12]=08;
buffer[13]=00;
buffer[23]=06;

/* starting cycles */

before=ReadTsc();

/**Start of Targeted code
**/

test= buffer[12] | buffer[13] | buffer[23] ;

switch( test )

{

case  12:
   asm(" jmp proc_1");

case  13:
asm("jmp proc_2");
case  14:
asm("jmp proc_3");
case  15:
asm("jmp proc_4");
default :
asm("jmp proc_5");

}



asm(" proc_5:");

/**End of Targeted code **/
  /*current cycles */
  clocks=ReadTsc() ;

clocks=clocks - before;
printf("\n cycles consumed %lu \n",clocks - overhead);

/**/

The overhead varies from generally 360  to 395 cycles .Sometimes it
also reduces close to 270 cycles.

Cycles consumed by the targetd code varies from 20 to 100
cycles.Theoratically i thing cycles consumed should be less than
20.Then why so many cycles  ? and the output vary from 20 to 100
cycles .Sometimes it crosses 100 cycles as well.

Sometimes the cycles consumed by targetted code become far less that
the RDTSC instrucion overhead.

Is there better way to write above code.I even used the prefetch
instruction  before the targeted code to make sure that buffer is in
the L1 cache but no success.

The code for ReadTsc() is as follows.Please also tell me if its
correct way to measure cycles .


/*/

typedef long long __int64;

__int64 ReadTSC() {
  int res[2];  // store 64 bit result here
  #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
  // Inline assembly in AT&T syntax
  #if defined (_LP64)  // 64 bit mode
 __asm__ __volatile__  (   // serialize (save rbx)
 "xorl %%eax,%%eax \n push %%rbx \n cpuid \n"
  ::: "%rax", "%rcx", "%rdx");
 __asm__ __volatile__  (   // read TSC, store edx:eax in res
 "rdtsc\n"
  : "=a" (res[0]), "=d" (res[1]) );
 __asm__ __volatile__  (   // serialize again
 "xorl %%eax,%%eax \n cpuid \n pop %%rbx \n"
  ::: "%rax", "%rcx", "%rdx");
  #else// 32 bit mode
 __asm__ __volatile__  (   // serialize (save ebx)
 "xorl %%eax,%%eax \n pushl %%ebx \n cpuid \n"
  ::: "%eax", "%ecx", "%edx");
 __asm__ __volatile__  (   // read TSC, store edx:eax in res
 "rdtsc\n"
  : "=a" (res[0]), "=d" (res[1]) );
 __asm__ __volatile__  (   // serialize again
 "xorl %%eax,%%eax \n cpuid \n popl %%ebx \n"
  ::: "%eax", "%ecx", "%edx");
  #endif
  #else
  // Inline assembly in MASM syntax
 __asm {
xor eax, eax
cpuid  // serialize
rdtsc  // read TSC
mov dword ptr res, eax // store low dword in res[0]
mov dword ptr res+4, edx   // store high dword in res[1]
xor eax, eax
cpuid  // serialize again
 };
  #endif   // __GNUC__
  return *(__int64*)res;   // return result
}


/*/


thanks,
shahzad
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


bechmarking kernel code

2007-05-03 Thread kernel coder

hi,
I'm profiling some part of kernel code.Mine profiling mechanism
is based on rdtsc instruction.

Please tell me if i'm profiling correctly.I'm teting linux kernel
2.6.15 and mine system is P4.


function(){

unsigned long long c1,c2,c3,c4,c5;
before=readtsc();
before=readtsc();
before=readtsc();
overhead=readtsc()-before;
c1=testfunc();
c2=testfunc();
c3=testfunc();
c4=testfunc();
c5=testfunc();

printk(" \n *c1 = %llu c2= %llu c3 = %llu c4 = %llu c5 = %llu overhead
=%llu",cycles1,cycles2,cycles3,cycles4,cycles5,overhead);


}

/***/


unsigned long long readtsc(){
unsigned long res[2]={0,0};
 __asm__ __volatile__  (
  "rdtsc\n"
   : "=a" (res[0]), "=d" (res[1]) );

return *((unsigned long long *)res);

}

/***/

unsigned long long testfunc(){
unsigned long start_cycles[2]={0,0};
unsigned long end_cycles[2]={0,0};
unsigned long long total_cycles=0;
int i;
 __asm__ __volatile__  (   // read TSC, store edx:eax in res
  "rdtsc\n"
   : "=a" (start_cycles[0]), "=d" (start_cycles[1]) );


  /*  CODE TO BE PROFILED */


 __asm__ __volatile__  (   // read TSC, store edx:eax in res
  "rdtsc\n"
   : "=a" (end_cycles[0]), "=d" (end_cycles[1]) );
total_cycles=*((unsigned long long *)end_cycles) - *((unsigned long
long *)start_cycles);
return total_cycles;
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/