Picon
Favicon
Gravatar

/proc help

Hi guys,

I want to find the number of threads owned by the caller process who tried to read from my proc file, how do I find the stuct responsible for it?
Also, I want to know the thread id of my caller.
I am writing a kernel module. Please help.

Thanks,
Suren.
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies <at> kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
michi1 | 9 Feb 19:12

Re: How to measure performance inside Kernel?

Hi!

On 10:58 Thu 09 Feb     , Peter Senna Tschudin wrote:
...
> But I want to repeat the tests on specific portion of code, not on
> entire application. Is there a safe way of do something like:
> 
> start_bench ( ?? ); /* start measurement */
> 
> buf_ptr_end = q->bufs[q->num_buffers];
> 
> for (buf_ptr = q->bufs[0]; buf_ptr < buf_ptr_end; ++buf_ptr)
>        buf_ptr->state = VB2_BUF_STATE_DEQUEUED;
> 
> end_bench ( ?? ); /* end measurement */

Yes, you can do this. If you search for a way for time measurement, take a
look at include/linux/ktime.h .

> And is this the correct approach for testing the performance of
> specific portion of Kernel code?

Why not? I would be a be worried about how the cpu-cache effects the
measurement, especially because your benchmark already showed that a
significant time is spent there.

	-Michi
--

-- 
programing a layer 3+4 network protocol for mesh networks
see http://michaelblizek.twilightparadox.com
Picon
Gravatar

How to measure performance inside Kernel?

Dear list,

I'm looking for a way to compare the performance of two different
codes inside Kernel. I was able to do some comparison on user land but
I want to test the specific portion of code inside Kernel.

At line 1195 of drivers/media/video/videobuf2-core.c:
/*
 * Reinitialize all buffers for next use.
 */
for (i = 0; i < q->num_buffers; ++i)
       q->bufs[i]->state = VB2_BUF_STATE_DEQUEUED;

With:

/* buf2 */
/*
 * Reinitialize all buffers for next use.
 */
buf_ptr_end = q->bufs[q->num_buffers];

for (buf_ptr = q->bufs[0]; buf_ptr < buf_ptr_end; ++buf_ptr)
       buf_ptr->state = VB2_BUF_STATE_DEQUEUED;

To test on user land I've created two separate C source codes and
compiled with gcc -O2, then used the "perf" tool on the entire
application. With num_buffers = 131072:

$ perf stat -e cycles,stalled-cycles-frontend,stalled-cycles-backend,cache-references,cache-misses
-r 2048 ./buf1

Performance counter stats for './buf1' (2048 runs):

16,538,039 cycles                #0.000 GHz                  (+-0.06%)[80.23%]
6,917,411 stalled-cycles-frontend#41.83% frontend cycles idle(+-0.14%)[80.25%]
4,686,384 stalled-cycles-backend #28.34% backend  cycles idle(+-0.14%)[80.28%]
148,990 cache-references                                     (+-0.38%)[80.24%]
71,180 cache-misses              #47.775 % of all cache refs (+-0.22%)[88.14%]

0.005234340 seconds time elapsed

$ perf stat -e cycles,stalled-cycles-frontend,stalled-cycles-backend,cache-references,cache-misses
-r 2048 ./buf2
Performance counter stats for './buf2' (2048 runs):

14,740,563 cycles                #0.000 GHz                  (+-0.04%)[77.89%]
5,187,716 stalled-cycles-frontend#35.19% frontend cycles idle(+-0.14%)[77.81%]
3,383,748 stalled-cycles-backend #
101,894 cache-references                                     (+-0.23%)[84.60%]
66,647 cache-misses              #65.408 % of all cache refs (+-0.14%)[90.52%]

0.004661826 seconds time elapsed                             (+-0.06%)

But I want to repeat the tests on specific portion of code, not on
entire application. Is there a safe way of do something like:

start_bench ( ?? ); /* start measurement */

buf_ptr_end = q->bufs[q->num_buffers];

for (buf_ptr = q->bufs[0]; buf_ptr < buf_ptr_end; ++buf_ptr)
       buf_ptr->state = VB2_BUF_STATE_DEQUEUED;

end_bench ( ?? ); /* end measurement */

And is this the correct approach for testing the performance of
specific portion of Kernel code?

Thank you!

Peter

--

-- 
Peter Senna Tschudin
peter.senna <at> gmail.com
gpg id: 48274C36
Abhijit Pawar | 9 Feb 07:10
Picon

Get USB Device Class Type and Mount point

Hi ,
Is there any way we can get the class type of the attached USB device through struct usb_device in a kernel module?

I tried getting the device descriptor and interface descriptor and then use them to get the Device and Interface Class and Subclass.

struct usb_device_descriptor *descriptor = &usbDev->descriptor;
 
struct usb_interface_descriptor *idesc = to_usb_interface(usbDev);

Whenever I run my kernel module, I get 0 for DeviceClass and Interface Class. I checked the meaning and it says its the information and to be gathered through interface.

Am I missing something here? What I want is to get the mount point / device path of the USB devices. Like for Storage Device I would like to get its mount path and for HID I would like to get its device path.

Regards,
Abhijit Pawar

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies <at> kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Picon
Gravatar

Re: Google Summer of Code 2012

Hi Greg, :-)

> kernelnewbies has not been involved in GSoC before, there are different
> groups handling kernel related projects with GSoC.  PSU and the Linux
> Foundation are two of them.

I asked here due:

http://www.linuxfoundation.org/collaborate/workgroups/gsoc/2011-gsoc-kernel-work

Any idea about how to get involved in Linux Foundation Google Summer of code?

Thank you!

--
Peter Senna Tschudin
peter.senna <at> gmail.com
gpg id: 48274C36

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies <at> kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Jack David | 8 Feb 14:00
Picon
Gravatar

Re: 答复: parent inode from the current struct inode

2012/2/8 Tom Lai(IT) <tomlai <at> utstar.com>:
> Hi Philipp,
>
> I checked 2.6.32 that dentry struct contained parent dentry struct.
>
>
> Hi Jack,
>
> On Wed, Feb 8, 2012 at 8:48 AM, Jack David <jd6589 <at> gmail.com> wrote:
>> Hi All,
>>
>> Is possible to get parent directory's inode structure from the current
>> inode? If so, how can I do that?
>
> It should be possible to use the container_of macro to get the parent
> dentry struct. Then, you can get the parent dentry d_parent and access
> its inode. (Please correct me, if I'm wrong. I didn't test it).
>

Okay, I tried container_of, but it did not work. So I tried
d_obtain_alias() which worked.

But I am not sure if I  have to make a call to dput() as well in order
to free the dentry obtained.
Anyone can confirm this?

J

>
>
> Philipp
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies <at> kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

--

-- 
J
Mayank Agarwal | 8 Feb 12:59
Picon
Gravatar

Contribute to linux kernel

Dear Experts,

I want to contribute to linux kernel in camera drivers or in any of the multimedia related driver development linux kernel job.
Please send me the details how can i start doing this.

Thanks and Regards,
Mayank

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies <at> kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Picon
Gravatar

Google Summer of Code 2012

Hello,

Are there plans for 2012 GSoC Kernel works? Is this the right place for asking?

Regards,

Peter

--

-- 
Peter Senna Tschudin
peter.senna <at> gmail.com
gpg id: 48274C36
Mayank Agarwal | 8 Feb 10:10
Picon
Gravatar

Re: Kernelnewbies Digest, Vol 15, Issue 12

Hi all,

I want to contribute to camera drivers in linux kernel.Please guide me the procedure of doing that.

Regards,
Mayank

On Tue, Feb 7, 2012 at 10:30 PM, <kernelnewbies-request <at> kernelnewbies.org> wrote:
Send Kernelnewbies mailing list submissions to
       kernelnewbies <at> kernelnewbies.org

To subscribe or unsubscribe via the World Wide Web, visit
       http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
or, via email, send a message with subject or body 'help' to
       kernelnewbies-request <at> kernelnewbies.org

You can reach the person managing the list at
       kernelnewbies-owner <at> kernelnewbies.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Kernelnewbies digest..."


Today's Topics:

  1. Re: "Trying to free already-free IRQ 9", but it wasn't freed
     by me (mayur nande)
  2. Re: request_firmware question (Greg KH)
  3. Re: fork() and exec() (Bernd Petrovitsch)
  4. Re: make config errors while building kernel on Fedora 16
     (Kartik Singhal)


----------------------------------------------------------------------

Message: 1
Date: Tue, 7 Feb 2012 20:33:31 +0530
From: mayur nande <mayur.nan <at> gmail.com>
Subject: Re: "Trying to free already-free IRQ 9", but it wasn't freed
       by me
To: "nils.stec" <nils.stec <at> googlemail.com>
Cc: kernelnewbies <Kernelnewbies <at> kernelnewbies.org>
Message-ID:
       <CA+fM3Xy2QALrjbTYJxW0yKn-Q-Y99Wi8xUyyWtKEzYDTByTkjQ <at> mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Hi Nils,

>>void cleanup_module(void) {
 >>   ...
 >>  free_irq(ADC_IRQ, NULL);        /* remove interrupt handler */
 >>  ...
 >>   return;
>>}

You should not pass NULL here. It should be the unique cookie that you
passed in request_irq (adc_irq_handler in your case) since you have used
IRQF_SHARED which means you want to share your interrupt line. Also check
whether you really want to share your interrupt line and also if you want
to use "(void *)(adc_irq_handler)" as the unique identification.

HTH!

Regards
Mayur

On Tue, Feb 7, 2012 at 7:45 PM, nils.stec <nils.stec <at> googlemail.com> wrote:

>  Hi,
>
> atm I'm writing a kernel module for an embedded ARM device.
> This module uses IRQ9.
>
> If i remove the module, the kernel tells me that:
>
> ------------[ cut here ]------------
> WARNING: at kernel/irq/manage.c:858 __free_irq+0x84/0x154()
> Trying to free already-free IRQ 9
> Modules linked in: adc_demo_irq(P-) g_ether pegasus mii
> [<c0028794>] (unwind_backtrace+0x0/0xd0) from [<c003b504>]
> (warn_slowpath_common+0x48/0x60)
> [<c003b504>] (warn_slowpath_common+0x48/0x60) from [<c003b554>]
> (warn_slowpath_fmt+0x24/0x30)
> [<c003b554>] (warn_slowpath_fmt+0x24/0x30) from [<c005fa00>]
> (__free_irq+0x84/0x154)
> [<c005fa00>] (__free_irq+0x84/0x154) from [<c005fb0c>]
> (free_irq+0x3c/0x5c)
> [<c005fb0c>] (free_irq+0x3c/0x5c) from [<bf01e18c>]
> (cleanup_module+0x4c/0x60 [adc_demo_irq])
> [<bf01e18c>] (cleanup_module+0x4c/0x60 [adc_demo_irq]) from [<c005b898>]
> (sys_delete_module+0x1c4/0x238)
> [<c005b898>] (sys_delete_module+0x1c4/0x238) from [<c0022dc0>]
> (ret_fast_syscall+0x0/0x28)
> ---[ end trace 60d7a16d878ac0b3 ]---
> adc testing module removed
> ------------[ cut here ]------------
>
> The message "adc testing module removed" comes from my module **after**free_irq() via printk, so the module exit routine works till the end.
>
> This is my code (only the IRQ related part):
>
> irqreturn_t adc_irq_handler(int irq, void *dev_id) {
>
>     ... do someting ...
>
>     return IRQ_HANDLED;
> }
>
> int init_module(void) {
>     int32_t retval;
>     ...
>     retval = request_irq(ADC_IRQ, adc_irq_handler, IRQF_SHARED, "lpc313x
> adc irq", (void *)(adc_irq_handler));
>     ...
>     return retval;
> }
>
> void cleanup_module(void) {
>     ...
>     free_irq(ADC_IRQ, NULL);        /* remove interrupt handler */
>     ...
>     return;
> }
>
>
> I hope anyone of you can help me with that problem. If you need more
> information, i'll send it
>
> Greetings,
> Nils
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies <at> kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20120207/79cf9412/attachment-0001.html

------------------------------

Message: 2
Date: Tue, 7 Feb 2012 07:07:50 -0800
From: Greg KH <greg <at> kroah.com>
Subject: Re: request_firmware question
To: anish kumar <anish198519851985 <at> gmail.com>
Cc: Kernelnewbies <at> kernelnewbies.org
Message-ID: <20120207150750.GA7583 <at> kroah.com>
Content-Type: text/plain; charset=us-ascii

On Tue, Feb 07, 2012 at 12:51:42AM -0800, anish kumar wrote:
> Hi,
>
> Now I have switched to using request_firmware api
> and after using firmware, memory is being released.
> Does it save kernel memory compare to case when
> I am having a having a local static firmware buffer(very big)
> from which I used to get the firmware and write it
> to the chip?
>
> As I know request_firmware api has several advantages
> but what I want to know is the advantages related
> to kernel memory footprint.

Yes it is, as well as using the "proper" api for firmware loading, which
means it fits into the rest of the kernel correctly.

Also, no new drivers will be accepted that have static firmware blobs.

greg k-h



------------------------------

Message: 3
Date: Tue, 07 Feb 2012 16:40:13 +0100
From: Bernd Petrovitsch <bernd <at> petrovitsch.priv.at>
Subject: Re: fork() and exec()
To: Vijay Chauhan <kernel.vijay <at> gmail.com>
Cc: kernelnewbies <at> kernelnewbies.org
Message-ID: <1328629213.25984.123.camel <at> thorin>
Content-Type: text/plain; charset="UTF-8"

On Die, 2012-02-07 at 00:38 +0530, Vijay Chauhan wrote:
> Hi List,
>
> I am learning Linux and trying to understand exec and fork function.
> execl says that it overlays the running address space. What does it mean?
>
> I created the following program and used top command with
> intentionally wrong arguments:
>
> #include<stdio.h>
> #include<unistd.h>
> #include<sys/types.h>
> #include<stdlib.h>
>
> int main(){
>       int a = -1;
>       if(fork()==0){
>               printf("Inside child\n");
>               printf("child pid=%d, parentid=%d\n", getpid(), getppid());
>               execl("/usr/bin/top", "/usr/bin/top", ">/dev/null" ,(char*)0 );

You get here only if the execl() as such fails.

>               scanf("inside child provide a %d", &a);

You should check the return value here if you actually got a matching
parameter.
scanf() is actually a function to be avoided.

>               printf("Inside child a=%d\n", a);
>               exit(1);
>       } else {
>               printf("Inside parent, going to wait\n");
>               printf("my pid=%d, parentid=%d\n", getpid(), getppid());
>               scanf("input parent %d\n", &a);

You should check the return value here if you actually got a matching
parameter.
scanf() is actually a function to be avoided.

>               wait(NULL);

You should check the return value here to know why "wait()" returns.

>               printf("Wait over\n");
>               printf("Inside parent a=%d\n", a);
>       }
>       return 0;
> }

       Bernd
--
Bernd Petrovitsch                  Email : bernd <at> petrovitsch.priv.at
                    LUGA : http://www.luga.at




------------------------------

Message: 4
Date: Tue, 7 Feb 2012 22:10:46 +0530
From: Kartik Singhal <kartiksinghal <at> gmail.com>
Subject: Re: make config errors while building kernel on Fedora 16
To: Mulyadi Santosa <mulyadi.santosa <at> gmail.com>
Cc: Kernelnewbies <at> kernelnewbies.org
Message-ID:
       <CAAY3Td5UJYmtqM5mzkBHug5bfMx0q5CoBd5CowtDNTdVrTORTQ <at> mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On Mon, Feb 6, 2012 at 1:05 PM, Mulyadi Santosa
<mulyadi.santosa <at> gmail.com>wrote:

> have you check their checksums?


Is there a way to verify the checksums for git clones as in my case?

--
Kartik
http://k4rtik.wordpress.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20120207/3ff99cbf/attachment-0001.html

------------------------------

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies <at> kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


End of Kernelnewbies Digest, Vol 15, Issue 12
*********************************************

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies <at> kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Picon
Favicon
Gravatar

/proc question

Hello All,

I am writing a kernel module and I wanted to know which data structure backs up the /proc/self or how do I get the process id of my call and number of it's threads from within the kernel?

Thanks,
Suren.
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies <at> kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Jack David | 8 Feb 08:48
Picon
Gravatar

parent inode from the current struct inode

Hi All,

Is possible to get parent directory's inode structure from the current
inode? If so, how can I do that?
Also, is it possible to get the "struct file" if we have "struct inode" ??

Thanks,
J

Gmane