lkml.org 
[lkml]   [2007]   [Oct]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
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?

Heiko,
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.

Ingo,
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 <vatsa@linux.vnet.ibm.com>
Signed-off-by : Dhaval Giani <dhaval@linux.vnet.ibm.com>


---
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_del(kobj);

+ kobject_uevent(kobj, KOBJ_ADD);
+
done:
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");
kobject_init(&uids_kobject);

@@ -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);
kobject_del(kobj);

sched_destroy_user(up);


--
Regards,
vatsa
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]

Ex:

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.

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

cd /etc/hotplug
. ./hotplug.functions

case $ACTION in

add)
uid=${DEVPATH##*/}
line=`grep -w $uid /etc/user_cpu_share.conf`
if [ $? -eq 0 ]
then
cpu_share=`echo $line | awk '{print $2}'`
echo $cpu_share > /sys/$DEVPATH/cpu_share
fi
;;
*)
;;
esac





\
 
 \ /
  Last update: 2007-10-09 17:03    [from the cache]
©2003-2014 Jasper Spaans. Advertise on this site