summaryrefslogtreecommitdiff
path: root/udev
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@vrfy.org>2008-09-09 15:14:38 +0200
committerKay Sievers <kay.sievers@vrfy.org>2008-09-09 15:14:38 +0200
commit3bc7c84cf07eae90aee2a0972a4441652e4d38f6 (patch)
treecc7bd4cf3fde2bd021e499e75cbbe8569781a6dd /udev
parentbd770e018301edd34c53d276872865ca13e824fa (diff)
udevd: remove max_childs_running logic
This was needed in the old days, where all the hotplug scripts did nothing better than sleep for seconds to work around timing issues. It made sure, that w continued to fork processes, while the machine was doing nothing than sleeping, but the maximim number of childs was already reached. This is no longer needed today, we do not run many of these scripts anymore.
Diffstat (limited to 'udev')
-rw-r--r--udev/lib/libudev-ctrl.c13
-rw-r--r--udev/lib/libudev-private.h2
-rw-r--r--udev/udevadm-control.c17
-rw-r--r--udev/udevadm.xml7
-rw-r--r--udev/udevd.c159
5 files changed, 5 insertions, 193 deletions
diff --git a/udev/lib/libudev-ctrl.c b/udev/lib/libudev-ctrl.c
index b2af0c73ed..ed42a3b231 100644
--- a/udev/lib/libudev-ctrl.c
+++ b/udev/lib/libudev-ctrl.c
@@ -201,12 +201,6 @@ int udev_ctrl_send_set_max_childs(struct udev_ctrl *uctrl, int count)
return 0;
}
-int udev_ctrl_send_set_max_childs_running(struct udev_ctrl *uctrl, int count)
-{
- ctrl_send(uctrl, UDEV_CTRL_SET_MAX_CHILDS_RUNNING, count, NULL);
- return 0;
-}
-
struct udev_ctrl_msg *udev_ctrl_receive_msg(struct udev_ctrl *uctrl)
{
struct udev_ctrl_msg *uctrl_msg;
@@ -323,10 +317,3 @@ int udev_ctrl_get_set_max_childs(struct udev_ctrl_msg *ctrl_msg)
return ctrl_msg->ctrl_msg.intval;
return -1;
}
-
-int udev_ctrl_get_set_max_childs_running(struct udev_ctrl_msg *ctrl_msg)
-{
- if (ctrl_msg->ctrl_msg.type == UDEV_CTRL_SET_MAX_CHILDS_RUNNING)
- return ctrl_msg->ctrl_msg.intval;
- return -1;
-}
diff --git a/udev/lib/libudev-private.h b/udev/lib/libudev-private.h
index d626fe65ee..53a58cc619 100644
--- a/udev/lib/libudev-private.h
+++ b/udev/lib/libudev-private.h
@@ -85,7 +85,6 @@ extern int udev_ctrl_send_start_exec_queue(struct udev_ctrl *uctrl);
extern int udev_ctrl_send_reload_rules(struct udev_ctrl *uctrl);
extern int udev_ctrl_send_set_env(struct udev_ctrl *uctrl, const char *key);
extern int udev_ctrl_send_set_max_childs(struct udev_ctrl *uctrl, int count);
-extern int udev_ctrl_send_set_max_childs_running(struct udev_ctrl *uctrl, int count);
struct udev_ctrl_msg;
extern struct udev_ctrl_msg *udev_ctrl_msg(struct udev_ctrl *uctrl);
extern struct udev_ctrl_msg *udev_ctrl_receive_msg(struct udev_ctrl *uctrl);
@@ -97,7 +96,6 @@ extern int udev_ctrl_get_start_exec_queue(struct udev_ctrl_msg *ctrl_msg);
extern int udev_ctrl_get_reload_rules(struct udev_ctrl_msg *ctrl_msg);
extern const char *udev_ctrl_get_set_env(struct udev_ctrl_msg *ctrl_msg);
extern int udev_ctrl_get_set_max_childs(struct udev_ctrl_msg *ctrl_msg);
-extern int udev_ctrl_get_set_max_childs_running(struct udev_ctrl_msg *ctrl_msg);
/* libudev-utils */
extern ssize_t util_get_sys_subsystem(struct udev *udev, const char *devpath, char *subsystem, size_t size);
diff --git a/udev/udevadm-control.c b/udev/udevadm-control.c
index c710811ed4..3dc7a1b52c 100644
--- a/udev/udevadm-control.c
+++ b/udev/udevadm-control.c
@@ -42,7 +42,6 @@ static void print_help(void)
" --reload-rules reloads the rules files\n"
" --env=<KEY>=<value> set a global environment variable\n"
" --max-childs=<N> maximum number of childs\n"
- " --max-childs-running=<N> maximum number of childs running at the same time\n"
" --help print this help text\n\n");
}
@@ -64,8 +63,6 @@ int udevadm_control(struct udev *udev, int argc, char *argv[])
{ "env", 1, NULL, 'e' },
{ "max-childs", 1, NULL, 'm' },
{ "max_childs", 1, NULL, 'm' + 256},
- { "max-childs-running", 1, NULL, 'M' },
- { "max_childs_running", 1, NULL, 'M' + 256},
{ "help", 0, NULL, 'h' },
{}
};
@@ -139,16 +136,6 @@ int udevadm_control(struct udev *udev, int argc, char *argv[])
udev_ctrl_send_set_max_childs(uctrl, i);
rc = 0;
break;
- case 'M':
- case 'M' + 256:
- i = strtoul(optarg, &endp, 0);
- if (endp[0] != '\0' || i < 1) {
- fprintf(stderr, "invalid number '%s'\n", optarg);
- goto exit;
- }
- udev_ctrl_send_set_max_childs_running(uctrl, i);
- rc = 0;
- break;
case 'h':
print_help();
rc = 0;
@@ -187,10 +174,6 @@ int udevadm_control(struct udev *udev, int argc, char *argv[])
udev_ctrl_send_set_max_childs(uctrl, strtoul(&arg[strlen("max_childs=")], NULL, 0));
rc = 0;
goto exit;
- } else if (!strncmp(arg, "max_childs_running=", strlen("max_childs_running="))) {
- udev_ctrl_send_set_max_childs_running(uctrl, strtoul(&arg[strlen("max_childs_running=")], NULL, 0));
- rc = 0;
- goto exit;
} else if (!strncmp(arg, "env", strlen("env"))) {
udev_ctrl_send_set_env(uctrl, &arg[strlen("env=")]);
rc = 0;
diff --git a/udev/udevadm.xml b/udev/udevadm.xml
index 075890845b..b86b33ac44 100644
--- a/udev/udevadm.xml
+++ b/udev/udevadm.xml
@@ -291,13 +291,6 @@
</listitem>
</varlistentry>
<varlistentry>
- <term><option>--max-childs-running=<replaceable>value</replaceable></option></term>
- <listitem>
- <para>Set the maximum number of events, which are allowed to run at the
- same time.</para>
- </listitem>
- </varlistentry>
- <varlistentry>
<term><option>--help</option></term>
<listitem>
<para>Print help text.</para>
diff --git a/udev/udevd.c b/udev/udevd.c
index a711df53d4..a24ca92517 100644
--- a/udev/udevd.c
+++ b/udev/udevd.c
@@ -54,8 +54,6 @@
/* maximum limit of forked childs */
#define UDEVD_MAX_CHILDS 256
-/* start to throttle forking if maximum number of running childs in our session is reached */
-#define UDEVD_MAX_CHILDS_RUNNING 16
static int debug;
@@ -95,7 +93,6 @@ static struct udev_rules rules;
static struct udev_ctrl *udev_ctrl;
static int uevent_netlink_sock = -1;
static int inotify_fd = -1;
-static pid_t sid;
static int signal_pipe[2] = {-1, -1};
static volatile int sigchilds_waiting;
@@ -104,7 +101,6 @@ static volatile int reload_config;
static int run_exec_q;
static int stop_exec_q;
static int max_childs;
-static int max_childs_running;
static char udev_log_env[32];
static LIST_HEAD(exec_list);
@@ -348,114 +344,6 @@ static int mem_size_mb(void)
return memsize;
}
-static int cpu_count(void)
-{
- FILE* f;
- char buf[4096];
- int count = 0;
-
- f = fopen("/proc/stat", "r");
- if (f == NULL)
- return -1;
-
- while (fgets(buf, sizeof(buf), f) != NULL) {
- if (strncmp(buf, "cpu", 3) == 0 && isdigit(buf[3]))
- count++;
- }
-
- fclose(f);
- if (count == 0)
- return -1;
- return count;
-}
-
-static int running_processes(void)
-{
- FILE* f;
- char buf[4096];
- int running = -1;
-
- f = fopen("/proc/stat", "r");
- if (f == NULL)
- return -1;
-
- while (fgets(buf, sizeof(buf), f) != NULL) {
- int value;
-
- if (sscanf(buf, "procs_running %u", &value) == 1) {
- running = value;
- break;
- }
- }
-
- fclose(f);
- return running;
-}
-
-/* return the number of process es in our session, count only until limit */
-static int running_processes_in_session(pid_t session, int limit)
-{
- DIR *dir;
- struct dirent *dent;
- int running = 0;
-
- dir = opendir("/proc");
- if (!dir)
- return -1;
-
- /* read process info from /proc */
- for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
- int f;
- char procdir[64];
- char line[256];
- const char *pos;
- char state;
- pid_t ppid, pgrp, sess;
- int len;
-
- if (!isdigit(dent->d_name[0]))
- continue;
-
- snprintf(procdir, sizeof(procdir), "/proc/%s/stat", dent->d_name);
- procdir[sizeof(procdir)-1] = '\0';
-
- f = open(procdir, O_RDONLY);
- if (f == -1)
- continue;
-
- len = read(f, line, sizeof(line)-1);
- close(f);
-
- if (len <= 0)
- continue;
- else
- line[len] = '\0';
-
- /* skip ugly program name */
- pos = strrchr(line, ')') + 2;
- if (pos == NULL)
- continue;
-
- if (sscanf(pos, "%c %d %d %d ", &state, &ppid, &pgrp, &sess) != 4)
- continue;
-
- /* count only processes in our session */
- if (sess != session)
- continue;
-
- /* count only running, no sleeping processes */
- if (state != 'R')
- continue;
-
- running++;
- if (limit > 0 && running >= limit)
- break;
- }
- closedir(dir);
-
- return running;
-}
-
static int compare_devpath(const char *running, const char *waiting)
{
int i;
@@ -524,8 +412,10 @@ static int devpath_busy(struct udevd_uevent_msg *msg, int limit)
/* check run queue for still running events */
list_for_each_entry(loop_msg, &running_list, node) {
- if (limit && childs_count++ > limit) {
- dbg(msg->udev, "%llu, maximum number (%i) of childs reached\n", msg->seqnum, childs_count);
+ childs_count++;
+
+ if (childs_count++ >= limit) {
+ info(msg->udev, "%llu, maximum number (%i) of childs reached\n", msg->seqnum, childs_count);
return 1;
}
@@ -565,27 +455,11 @@ static void msg_queue_manager(struct udev *udev)
{
struct udevd_uevent_msg *loop_msg;
struct udevd_uevent_msg *tmp_msg;
- int running;
if (list_empty(&exec_list))
return;
- running = running_processes();
- dbg(udev, "%d processes runnning on system\n", running);
- if (running < 0)
- running = max_childs_running;
-
list_for_each_entry_safe(loop_msg, tmp_msg, &exec_list, node) {
- /* check running processes in our session and possibly throttle */
- if (running >= max_childs_running) {
- running = running_processes_in_session(sid, max_childs_running+10);
- dbg(udev, "at least %d processes running in session\n", running);
- if (running >= max_childs_running) {
- dbg(udev, "delay seq %llu, too many processes already running\n", loop_msg->seqnum);
- return;
- }
- }
-
/* serialize and wait for parent or child events */
if (devpath_busy(loop_msg, max_childs) != 0) {
dbg(udev, "delay seq %llu (%s)\n", loop_msg->seqnum, loop_msg->devpath);
@@ -595,7 +469,6 @@ static void msg_queue_manager(struct udev *udev)
/* move event to run list */
list_move_tail(&loop_msg->node, &running_list);
udev_event_run(loop_msg);
- running++;
dbg(udev, "moved seq %llu to running list\n", loop_msg->seqnum);
}
}
@@ -735,12 +608,6 @@ static void handle_ctrl_msg(struct udev_ctrl *uctrl)
max_childs = i;
}
- i = udev_ctrl_get_set_max_childs_running(ctrl_msg);
- if (i > 0) {
- info(udev, "udevd message (SET_MAX_CHILDS_RUNNING) received, max_childs_running=%i\n", i);
- max_childs_running = i;
- }
-
udev_ctrl_msg_unref(ctrl_msg);
}
@@ -1079,10 +946,7 @@ int main(int argc, char *argv[])
chdir("/");
umask(022);
-
- /* become session leader */
- sid = setsid();
- dbg(udev, "our session is %d\n", sid);
+ setsid();
/* OOM_DISABLE == -17 */
fd = open("/proc/self/oom_adj", O_RDWR);
@@ -1149,19 +1013,6 @@ int main(int argc, char *argv[])
}
info(udev, "initialize max_childs to %u\n", max_childs);
- /* start to throttle forking if maximum number of _running_ childs is reached */
- value = getenv("UDEVD_MAX_CHILDS_RUNNING");
- if (value)
- max_childs_running = strtoull(value, NULL, 10);
- else {
- int cpus = cpu_count();
- if (cpus > 0)
- max_childs_running = 8 + (8 * cpus);
- else
- max_childs_running = UDEVD_MAX_CHILDS_RUNNING;
- }
- info(udev, "initialize max_childs_running to %u\n", max_childs_running);
-
/* clear environment for forked event processes */
clearenv();