[lkml]   [2007]   [Oct]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
    Patch in this message
    Subject[PATCH sched-devel] Generate uevents for user creation/destruction
    On Thu, Oct 04, 2007 at 10:54:51AM +0200, Heiko Carstens wrote:
    > > i'm wondering about the following: could not (yet) existing UIDs be made
    > > configurable too? I.e. if i do this in a bootup script:
    > >
    > > echo 2048 > /sys/kernel/uids/500/cpu_share
    > >
    > > this should just work too, regardless of there not being any UID 500
    > > tasks yet. Likewise, once configured, the /sys/kernel/uids/* directories
    > > (with the settings in them) should probably not go away either.
    > Shouldn't that be done via uevents? E.g. UID x gets added to the sysfs tree,
    > generates a uevent and a script then figures out the cpu_share and sets it.
    > That way you also don't need to keep the directories. No?

    Thanks for the hint. Here's a patch to enable generation of
    uevents for user creation/deletion. These uevents can be handled in
    userspace to configure a new user's cpu share.

    Note : After bootup I could test that new user's cpu share is configured
    as per a configuration file (/etc/user_cpu_share.conf). However this
    mechanism didnt work for root user. Perhaps uevent for root user is
    generated way too early?

    A HOWTO text file is also attached explaining how to make use of these
    uevents in userspace.

    This patch applies on top of latest sched-devel tree. Pls review
    and apply ..


    Generate uevents when a user is being created/destroyed. These events
    could be used to configure cpu share of a new user.

    Signed-off-by : Srivatsa Vaddagiri <>
    Signed-off-by : Dhaval Giani <>

    kernel/user.c | 4 ++++
    1 files changed, 4 insertions(+)

    Index: current/kernel/user.c
    --- current.orig/kernel/user.c
    +++ current/kernel/user.c
    @@ -174,6 +174,8 @@ static int user_kobject_create(struct us
    if (error)

    + kobject_uevent(kobj, KOBJ_ADD);
    return error;
    @@ -189,6 +191,7 @@ int __init uids_kobject_init(void)

    /* create under /sys/kernel dir */
    uids_kobject.parent = &kernel_subsys.kobj;
    + uids_kobject.kset = &kernel_subsys;
    kobject_set_name(&uids_kobject, "uids");

    @@ -228,6 +231,7 @@ static void remove_user_sysfs_dir(struct
    goto done;

    sysfs_remove_file(kobj, &up->user_attr.attr);
    + kobject_uevent(kobj, KOBJ_REMOVE);


    This HOWTO explains the steps required to configure a user's cpu share
    automatically when he/she logs in. This has been verified to work on
    a Redhat distribution.

    Note : This HOWTO is a *hack* to get things working quickly. In particular it
    doesn't follow standards like LSB.

    1. Create a file /etc/user_cpu_share.conf with this format:

    [uid] [cpu_share]


    512 1024 #user vatsa
    514 512 #user guest

    2. Create a script, named "kernel.agent" in /etc/hotplug directory
    as follows. Make that script executable and owned by root.

    # kernel hotplug agent for 2.6 kernels
    # ACTION=add
    # DEVPATH=/kernel/uids/[uid]

    cd /etc/hotplug
    . ./hotplug.functions

    case $ACTION in

    line=`grep -w $uid /etc/user_cpu_share.conf`
    if [ $? -eq 0 ]
    cpu_share=`echo $line | awk '{print $2}'`
    echo $cpu_share > /sys/$DEVPATH/cpu_share


     \ /
      Last update: 2007-10-09 17:03    [W:0.026 / U:35.588 seconds]
    ©2003-2017 Jasper Spaans. hosted at Digital OceanAdvertise on this site