export of SEQNUM to userspace
Subsystems (2)
Hi Greg,
we want to init HAL with the last emitted hotplug SEQNUM from the kernel. I think of a sysfs file we can read. It would solve the problem of the initial timeout, like we have with udevd too (the very first event is delayed).
What is a proper place to live for this beast?
Thanks,
Kay
-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_idP47&alloc_id808&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 5 lines · Kay Sievers
Hi Greg,
we want to init HAL with the last emitted hotplug SEQNUM from the kernel. I think of a sysfs file we can read. It would solve the problem of the initial timeout, like we have with udevd too (the very first event is delayed).
Ok, that sounds reasonable.
Quoted 1 line
What is a proper place to live for this beast?
I'm getting a lot of requests for odd stuff like this in sysfs. Things that are "kernel" specific, and aren't associated with any one place (things that would end up in /proc/sys/kernel if we didn't have sysfs.)
So, how about /sys/kernel?
thanks,
greg k-h
-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_idP47&alloc_id808&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 9 lines · Greg KH
Quoted 5 lines · Kay Sievers
Hi Greg,
we want to init HAL with the last emitted hotplug SEQNUM from the kernel. I think of a sysfs file we can read. It would solve the problem of the initial timeout, like we have with udevd too (the very first event is delayed).Ok, that sounds reasonable.
Quoted 7 lines
Quoted 1 line
What is a proper place to live for this beast?
I'm getting a lot of requests for odd stuff like this in sysfs. Things that are "kernel" specific, and aren't associated with any one place (things that would end up in
/proc/sys/kernelif we didn't have sysfs.)So, how about
/sys/kernel?
Sounds good!
Who should create the kset (or in this case it's a subsystem) for this? Any hints?
Thanks,
Kay
-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_idP47&alloc_id808&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 12 lines · Kay Sievers
Quoted 11 lines · Greg KH
Quoted 5 lines · Kay Sievers
Hi Greg,
we want to init HAL with the last emitted hotplug SEQNUM from the kernel. I think of a sysfs file we can read. It would solve the problem of the initial timeout, like we have with udevd too (the very first event is delayed).Ok, that sounds reasonable.
Quoted 1 line
What is a proper place to live for this beast?
Quoted 8 lines
Quoted 5 lines
I'm getting a lot of requests for odd stuff like this in sysfs. Things that are "kernel" specific, and aren't associated with any one place (things that would end up in
/proc/sys/kernelif we didn't have sysfs.)So, how about
/sys/kernel?Sounds good!
Who should create the kset (or in this case it's a subsystem) for this?
Hm, how about a new file in kernel/ ?
thanks,
greg k-h
-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_idP47&alloc_id808&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 17 lines · Greg KH
Quoted 16 lines · Kay Sievers
Quoted 15 lines · Greg KH
Quoted 5 lines · Kay Sievers
Hi Greg,
we want to init HAL with the last emitted hotplug SEQNUM from the kernel. I think of a sysfs file we can read. It would solve the problem of the initial timeout, like we have with udevd too (the very first event is delayed).Ok, that sounds reasonable.
Quoted 1 line
What is a proper place to live for this beast?
I'm getting a lot of requests for odd stuff like this in sysfs. Things that are "kernel" specific, and aren't associated with any one place (things that would end up in
/proc/sys/kernelif we didn't have sysfs.)
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
So, how about
/sys/kernel?Sounds good!
Who should create the kset (or in this case it's a subsystem) for this?Hm, how about a new file in
kernel/?
Something like this?
o /sys/kernel/hotplug_seqnum exports the current number
o lib/kobject.c's sequence_num is renamed to hotplug_seqnum and exported by include/linux/kobject.h
o the source file ksysfs.c in kernel/ creates on init the sybsystem "/sys/kernel/" in sysfs
Thanks,
Kay
kernel/ksysfs.c renamed from dev/null +63 -0
@@ -0,0 +1,63 @@ +/* +* kernel/ksysfs.c - sysfs attributes in /sys/kernel, which +* are not related to any other subsystem +* +* Copyright (C) 2004 Kay Sievers <[email protected]> +* +* This file is release under the GPLv2 +* +*/ + +#include <linux/config.h> +#include <linux/kobject.h> +#include <linux/string.h> +#include <linux/sysfs.h> +#include <linux/init.h> + +#define KERNEL_ATTR_RO (_name) \ +static struct subsys_attribute _name##_attr = { \ + .attr = { \ + .name = __stringify(_name), \ + .mode = 0444, \ + }, \ + .show = _name##_show, \ +} + +#define KERNEL_ATTR_RW (_name) \ +static struct subsys_attribute _name##_attr = { \ + .attr = { \ + .name = __stringify(_name), \ + .mode = 0644, \ + }, \ + .show = _name##_show, \ + .store = _name##_store, \ +} + +static ssize_t hotplug_seqnum_show (struct subsystem * subsys,char * page) +{ +return sprintf (page,"%lu\n" , hotplug_seqnum); +} +KERNEL_ATTR_RO (hotplug_seqnum); + + +decl_subsys (kernel,NULL ,NULL ); + +static struct attribute * g[] = { + &hotplug_seqnum_attr.attr, +NULL +}; + +static struct attribute_group attr_group = { + .attrs = g, +}; + +static int __init ksysfs_init (void ) +{ +int error =subsystem_register (&kernel_subsys); +if (!error) + error =sysfs_create_group (&kernel_subsys.kset.kobj,&attr_group); + +return error; +} + +core_initcall (ksysfs_init);
===== include/linux/kobject.h 1.31 vs edited =====
include/linux/kobject.h +3 -0
@@ -26,6 +26,9 @@#define KOBJ_NAME_LEN 20 +/* counter to tag the hotplug event, also available through sysfs */ +extern unsigned long hotplug_seqnum; +struct kobject {char * k_name;char name[KOBJ_NAME_LEN ];
===== kernel/Makefile 1.42 vs edited =====
kernel/Makefile +1 -1
@@ -7,7 +7,7 @@ obj-y = sched.o fork.o exec_domain.o sysctl.o capability.o ptrace.o timer.o user.o \ signal.o sys.o kmod.o workqueue.o pid.o \ rcupdate.o intermodule.o extable.o params.o posix-timers.o \ - kthread.o + kthread.o ksysfs.o obj-$(CONFIG_FUTEX) += futex.o obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o
===== lib/kobject.c 1.45 vs edited =====
lib/kobject.c +2 -2
@@ -122,7 +122,7 @@ char * kobject_get_path(struct kset *kse#define BUFFER_SIZE 1024/* should be enough memory for the env */ #define NUM_ENVP 32/* number of env pointers */ -static unsigned long sequence_num; +unsigned long hotplug_seqnum;static spinlock_t sequence_lock =SPIN_LOCK_UNLOCKED ; static void kset_hotplug(const char *action, struct kset *kset,
@@ -178,7 +178,7 @@ static void kset_hotplug(const char *act scratch +=sprintf (scratch,"ACTION=%s" , action) +1 ;spin_lock (&sequence_lock); - seq = sequence_num++; + seq = hotplug_seqnum++;spin_unlock (&sequence_lock); envp [i++] = scratch;
Quoted 7 lines · Kay Sievers
Something like this?
o
/sys/kernel/hotplug_seqnumexports the current number
o lib/kobject.c'ssequence_numis renamed tohotplug_seqnumand exported byinclude/linux/kobject.h
o the source fileksysfs.cinkernel/creates on init the sybsystem "/sys/kernel/" in sysfs
Nice, I like it. How about this, smaller version instead. I just changed your code to use the __ATTR* macros and named a few variables a bit better, no "g" variables for me :)
Is this ok with you?
thanks,
greg k-h
------
include/linux/kobject.h +3 -0
@@ -24,6 +24,9 @@#define KOBJ_NAME_LEN 20 +/* counter to tag the hotplug event, read only except for the kobject core */ +extern unsigned long hotplug_seqnum; +struct kobject {char * k_name;char name[KOBJ_NAME_LEN ];
kernel/Makefile +1 -1
@@ -7,7 +7,7 @@ sysctl.o capability.o ptrace.o timer.o user.o \ signal.o sys.o kmod.o workqueue.o pid.o \ rcupdate.o intermodule.o extable.o params.o posix-timers.o \ - kthread.o + kthread.o ksysfs.o obj-$(CONFIG_FUTEX) += futex.o obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o
kernel/ksysfs.c new file +52 -0
52 lines not on this page · raw message
lib/kobject.c +2 -2
@@ -120,7 +120,7 @@#define BUFFER_SIZE 1024/* should be enough memory for the env */ #define NUM_ENVP 32/* number of env pointers */ -static unsigned long sequence_num; +unsigned long hotplug_seqnum;static spinlock_t sequence_lock =SPIN_LOCK_UNLOCKED ; static void kset_hotplug(const char *action, struct kset *kset,
@@ -176,7 +176,7 @@ scratch +=sprintf (scratch,"ACTION=%s" , action) +1 ;spin_lock (&sequence_lock); - seq = sequence_num++; + seq = hotplug_seqnum++;spin_unlock (&sequence_lock); envp [i++] = scratch;
-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_idP47&alloc_id808&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 9 lines · Greg KH
Quoted 7 lines · Kay Sievers
Something like this?
o
/sys/kernel/hotplug_seqnumexports the current number
o lib/kobject.c'ssequence_numis renamed tohotplug_seqnumand exported byinclude/linux/kobject.h
o the source fileksysfs.cinkernel/creates on init the sybsystem "/sys/kernel/" in sysfs
Quoted 5 lines
Nice, I like it. How about this, smaller version instead. I just changed your code to use the __ATTR* macros and named a few variables a bit better, no "g" variables for me :)
Is this ok with you?
Sure, looks perfect.
Thanks a lot,
Kay
-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_idP47&alloc_id808&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 10 lines · Kay Sievers
Quoted 9 lines · Greg KH
Quoted 7 lines · Kay Sievers
Something like this?
o
/sys/kernel/hotplug_seqnumexports the current number
o lib/kobject.c'ssequence_numis renamed tohotplug_seqnumand exported byinclude/linux/kobject.h
o the source fileksysfs.cinkernel/creates on init the sybsystem "/sys/kernel/" in sysfs
Quoted 7 lines
Quoted 5 lines
Nice, I like it. How about this, smaller version instead. I just changed your code to use the __ATTR* macros and named a few variables a bit better, no "g" variables for me :)
Is this ok with you?
Sure, looks perfect.
Oops, too fast. New patch. Forgot the unusal CONFIG_* combinations.
!CONFIG_SYSFS goes with:
obj-$(CONFIG_SYSFS) += ksysfs.o
and
!CONFIG_HOTPLUG needs the ifdef's in ksysfs.c and kobject.h or is there any better way?
Tested compilation of all four combinations and booted with:CONFIG_SYSFS + !CONFIG_HOTPLUG.
Kay
Add /sys/kernel subsystem to sysfs and export current hotplug SEQUNUM
o /sys/kernel/hotplug_seqnum exports the current number¶
o lib/kobject.c's sequence_num is renamed to hotplug_seqnum and¶ exported by include/linux/kobject.h¶
o the source file ksysfs.c in kernel/ creates on init the¶ sybsystem "/sys/kernel/" in sysfs¶
include/linux/kobject.h +5 -0
@@ -26,6 +26,11 @@#define KOBJ_NAME_LEN 20 +#ifdef CONFIG_HOTPLUG +/* counter to tag the hotplug event, read only except for the kobject core */ +extern unsigned long hotplug_seqnum; +#endif +struct kobject {char * k_name;char name[KOBJ_NAME_LEN ];
kernel/Makefile +1 -0
@@ -24,6 +24,7 @@ obj-$(CONFIG_AUDIT) += audit.o obj-$(CONFIG_AUDITSYSCALL) += auditsc.o obj-$(CONFIG_KPROBES) += kprobes.o +obj-$(CONFIG_SYSFS) += ksysfs.o ifneq ($(CONFIG_IA64),y) # According to Alan Modra <[email protected]>, the -fno-omit-frame-pointer is
kernel/ksysfs.c new file +55 -0
55 lines not on this page · raw message
lib/kobject.c +2 -2
@@ -122,7 +122,7 @@#define BUFFER_SIZE 1024/* should be enough memory for the env */ #define NUM_ENVP 32/* number of env pointers */ -static unsigned long sequence_num; +unsigned long hotplug_seqnum;static spinlock_t sequence_lock =SPIN_LOCK_UNLOCKED ; static void kset_hotplug(const char *action, struct kset *kset,
@@ -178,7 +178,7 @@ scratch +=sprintf (scratch,"ACTION=%s" , action) +1 ;spin_lock (&sequence_lock); - seq = sequence_num++; + seq = hotplug_seqnum++;spin_unlock (&sequence_lock); envp [i++] = scratch;
Quoted 11 lines · Kay Sievers
Oops, too fast. New patch. Forgot the unusal CONFIG_* combinations.
!CONFIG_SYSFS goes with:
obj-$(CONFIG_SYSFS) += ksysfs.oand
!CONFIG_HOTPLUG needs the ifdef's inksysfs.candkobject.hor is there any better way?Tested compilation of all four combinations and booted with:
CONFIG_SYSFS+ !CONFIG_HOTPLUG.
Hm, we also need to change this:
Review
Quoted 2 lines
(quoted diff) +1
-1- seq = sequence_num++; + seq = hotplug_seqnum++;
To this:
seq = ++hotplug_seqnum;
to show the last used sequence number.
I'll make that change and test out the different config options.
thanks,
greg k-h
-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_idP47&alloc_id808&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Hi,
Quoted 8 lines · Kay Sievers
Hi Greg,
we want to init HAL with the last emitted hotplug SEQNUM from the kernel. I think of a sysfs file we can read. It would solve the problem of the initial timeout, like we have with udevd too (the very first event is delayed).What is a proper place to live for this beast?
Is this yet integrated?
Another thing, I was thinking, for this to be really useful I guess what we need is not (only?) the last emitted hotplug SEQNUM but instead the "maximum SEQNUM ever emitted". Because with the "last SEQNUM emitted" the kernel may emit this sequence of hotplug events
1004
1003
1002 <-- udevd starts; reads "last seqnum emitted is 1002" 1001 <-- udevd discards this hotplug event
1005 <-- udevd blocks/timeouts waiting for 1002 1006
1007
...
and we're as screwed as we are today. With "maximum SEQNUM ever emitted" it will work; proof is by contradiction.
Thoughts? Should we have both?
Thanks,
David
-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal Use IT products in your business? Tell us what you think of them. Give us Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 10 lines · David Zeuthen
Hi,
Quoted 6 lines · Kay Sievers
Hi Greg,
we want to init HAL with the last emitted hotplug SEQNUM from the kernel. I think of a sysfs file we can read. It would solve the problem of the initial timeout, like we have with udevd too (the very first event is delayed).
Quoted 4 lines
Quoted 2 lines
What is a proper place to live for this beast?
Is this yet integrated?
It's in the -mm tree, I'm waiting for 2.6.9 to come out before sending it for inclusion in the main kernel tree.
Quoted 8 lines
Another thing, I was thinking, for this to be really useful I guess what we need is not (only?) the last emitted hotplug SEQNUM but instead the "maximum SEQNUM ever emitted". Because with the "last SEQNUM emitted" the kernel may emit this sequence of hotplug events
1004
1003
1002 <-- udevd starts; reads "last seqnum emitted is 1002"
No, the read will read '1004', not 1002.
Quoted 8 lines
1001 <-- udevd discards this hotplug event
1005 <-- udevd blocks/timeouts waiting for 1002
1006
1007
...and we're as screwed as we are today. With "maximum SEQNUM ever emitted" it will work; proof is by contradiction.
The sysfs file will always show the "max SEQNUM" due to locking within the kernel keeping the order always correct.
Hope this helps,
greg k-h
-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal Use IT products in your business? Tell us what you think of them. Give us Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel