Re: Concurrent accesses to sysfs
On 06.09.2010 15:59, Greg KH wrote: On Mon, Sep 06, 2010 at 09:23:06AM +0200, Christophe Aeschlimann wrote: On 04.09.2010 02:58, Greg KH wrote: On Tue, Aug 24, 2010 at 11:52:07AM +0200, Christophe Aeschlimann wrote: Hi, I'm implementing a user-space API that will give access to custom hardware features through sysfs. This library is here to hide the sysfs specifics. Ick, don't. What's wrong with the existing sysfs interfaces we have today, open(), read(), close()? And what type of hardware features are you wanting to export through sysfs? Why sysfs? Well we have to offer a board-support-package to a customer. When I told them about sysfs to access LEDS / GPIOS they told me they wanted some layer above that so they can just call a switch_led_on function and they wouldn't have to know the way sysfs works. E.G. Know the sysfs path name, attributes names and values to write to the attributes to control the device. {sigh} Ok, then write a tiny shell script that does this :) I would like to know if something special must be done in this library to assure concurrent accesses. Here is an example : I want the users of my library to be able to switch-on/-off a LED using a simple function like the following : platform_led_on(0); //switches on led '0' platform_led_off(0); //switches on led '0' This led is declared in my platform_data in the board init file as a gpio_led and can be seen in sysfs under /sys/class/leds/led0 the platform_led_on/off(0) functions will : - build the sysfs path to the led0 based on the argument (0) - open the brightness file in the sysfs path - write to the brightness file a value != 0 to switch the led on or 0 to switch it off - close the brightness file - return Now what will happen if a thread tries to switch on the led while another thread tries to switch it off ? Who ever writes to the file first will cause their action to happen, followed by the action of the second process/thread. What happens with the open() on sysfs pseudo files ? The file descriptor is returned, what exactly are you worried about here? Can the file be opened twice ? Yes, multiple times, try it. Or does it requires a close first ? Nope. If you need locking, do it in your library, but again, this really looks like overkill, why do you need to do all of this? Because it's a customer request :) What type of locking are they asking for? Is it possible to do the locking with the open() or flock() ? Or should I use pthread mutex ? open() isn't going to work. flock() might, haven't tried it though. a mutex would, if you are controling all access through your library. But that's really overkill here, right? Oh, and you have looked at libudev, right? No I wasn't aware of that lib but I guess : udev_device_get_sysattr_value () does the open/read/close for me in a thread-safe way ? Again, what does thread-safe mean here? The above call opens the file and reads the value and then closes the file and returns the value to your program. If someone else went in and wrote to the file right after reading to it, your read will be stale. That makes it clear for me. Since I wasn't sure of the behaviour of open/close (exclusive / non-exclusive) and read/write (atomic/non-atomic) I was getting worried that it might not behave correctly. Which is the same thing that would happen with your mutex lock as well, right? You aren't going to ever be able to conclusivly say, Here is the value, no one else has changed it. Sure. So again, I think you are over thinking this a lot. Just wrap up the libudev call if you want, or just point your customer at libudev if they are writing their own programs. I think you got the point, I'm always over thinking :) I will wrap the libudev call and everything is going to be fine. Thanks for the help ! Regards, Christophe Or just write a simple shell script :) good luck, greg k-h -- Christophe Aeschlimann Embedded Software Engineer Advanced Communications Networks S.A. Rue du Puits-Godet 8a 2000 Neuchâtel, Switzerland Tél. +41 32 724 74 31 c.aeschlim...@acn-group.ch -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Integer Division on 32 Bit Machines
Hello, I have encountered a problem on my 32 bit machine. Here some code snippets: typedef signed long s64; asmlinkage long sys_optStopMeasure(int __user workamount) { s64 currentPerformance, currentTimePerWork; ... currentTimePerWork = currentPerformance / workamount; ... } When I run a make, I get this error at the end: LD vmlinux.o MODPOST vmlinux.o GEN .version CHK include/generated/compile.h UPD include/generated/compile.h CC init/version.o LD init/built-in.o LD .tmp_vmlinux1 optimizer/built-in.o: In function `sys_optStopMeasure': /source/trunk/linux-2.6.34/optimizer/sys_optStopMeasure.c:144: undefined reference to `__divdi3' Another person which has tried the code had no problems - he compiled the code for a 64 bit machine. Can you explain to me the problem? Why does the code work on 64 but not on 32 bit? I've looked for some workarounds and found do_div(). Is this the way to go? Or are there better ways? Thanks for your help! Andreas -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Query related to mount point identification.
Hi, I am currently working on parsing the packets for NFS protocol. I want to know, in case of a file operation, how can we identify the mount point where the file is mounted? E.g. scenario is- Client has mounted the node already. You apply the NFS parser and start reading/writing to the file. Here, parser did not know if the node is mounted or not (as we enabled the parser after mounting the node. And I want to identify that at the arrival of first packet). So is there any way to identify that based on the file name (or inode may be)? I am looking at the fstat() system call, but unable to find anything useful. Any pointers will be highly appreciated. -- Thanks, Nilesh -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: Integer Division on 32 Bit Machines
use do_div On Tue, Sep 7, 2010 at 1:02 PM, Andreas Leppert wu...@web.de wrote: Hello, I have encountered a problem on my 32 bit machine. Here some code snippets: typedef signed long s64; asmlinkage long sys_optStopMeasure(int __user workamount) { s64 currentPerformance, currentTimePerWork; ... currentTimePerWork = currentPerformance / workamount; ... } When I run a make, I get this error at the end: LD vmlinux.o MODPOST vmlinux.o GEN .version CHK include/generated/compile.h UPD include/generated/compile.h CC init/version.o LD init/built-in.o LD .tmp_vmlinux1 optimizer/built-in.o: In function `sys_optStopMeasure': /source/trunk/linux-2.6.34/optimizer/sys_optStopMeasure.c:144: undefined reference to `__divdi3' Another person which has tried the code had no problems - he compiled the code for a 64 bit machine. Can you explain to me the problem? Why does the code work on 64 but not on 32 bit? I've looked for some workarounds and found do_div(). Is this the way to go? Or are there better ways? Thanks for your help! Andreas -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
changing kernel variables at run time
How can one change the value of Kernel Variables at run time. -- Tapas -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: Query related to mount point identification.
On Tue, Sep 7, 2010 at 4:27 AM, Tayade, Nilesh nilesh.tay...@netscout.com wrote: Hi, I am currently working on parsing the packets for NFS protocol. I want to know, in case of a file operation, how can we identify the mount point where the file is mounted? E.g. scenario is- Client has mounted the node already. You apply the NFS parser and start reading/writing to the file. Here, parser did not know if the node is mounted or not (as we enabled the parser after mounting the node. And I want to identify that at the arrival of first packet). So is there any way to identify that based on the file name (or inode may be)? I am looking at the fstat() system call, but unable to find anything useful. Looks like given the filename you want to find the mountpoint. May be this will help. http://www.mail-archive.com/bug-coreut...@gnu.org/msg20630.html -- Thanks - Manish == [$\*.^ -- I miss being one of them == -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: Integer Division on 32 Bit Machines
On Tue, Sep 7, 2010 at 3:32 PM, Andreas Leppert wu...@web.de wrote: Hello, I have encountered a problem on my 32 bit machine. Here some code snippets: typedef signed long s64; Hi sorry my reply wont help you. Since I was reading this thread wanted to know what is the meaning of typedef signed long s64 I searched at Google but could not find it. -- Everything is okay in the end, if it's not ok, then it's not the end.
Re: Integer Division on 32 Bit Machines
Bond, On Tue, Sep 7, 2010 at 10:44 AM, Bond jamesbond.2...@gmail.com wrote: On Tue, Sep 7, 2010 at 3:32 PM, Andreas Leppert wu...@web.de wrote: Hello, I have encountered a problem on my 32 bit machine. Here some code snippets: typedef signed long s64; Hi sorry my reply wont help you. Since I was reading this thread wanted to know what is the meaning of typedef signed long s64 I searched at Google but could not find it. This should help: http://en.wikipedia.org/wiki/Typedef Thanks, Hiren -- Everything is okay in the end, if it's not ok, then it's not the end.
Re: changing kernel variables at run time
On Tue, Sep 7, 2010 at 10:29 AM, Tapas Mishra mightydre...@gmail.com wrote: How can one change the value of Kernel Variables at run time. Depending on what you what to change, you may want to look at /proc /sys -- Thanks - Manish == [$\*.^ -- I miss being one of them == -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: changing kernel variables at run time
On Wed, Sep 8, 2010 at 5:50 AM, Neependra Khare neependra.kh...@gmail.com wrote: On Tue, Sep 7, 2010 at 10:59 PM, Tapas Mishra mightydre...@gmail.com wrote: How can one change the value of Kernel Variables at run time. You can definitely use SystemTap's Guru mode for that. An specific example is given at:- http://www.redbooks.ibm.com/redpapers/pdfs/redp4469.pdf Thanks for the link. -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ