static unsigned int max_jobs;
static unsigned int job_count;
static unsigned int jobs_pending;
+static unsigned int max_jobs_pending;
int get_child_count(void)
{
return 0;
}
+static int deny_job(void)
+{
+ int ret;
+ char byte = -1;
+
+ pr_info("Denying new job. %d jobs currently and %d pending, "
+ "limit of pending jobs is %d\n",
+ job_count, jobs_pending, max_jobs_pending);
+
+ ret = write(job_get_permission_fd[1], &byte, 1);
+ if (ret != 1) {
+ pr_err("Failed to write 1 byte: %m\n");
+ return -1;
+ }
+
+ return 0;
+}
+
static int handle_job_request(struct event_handler *h)
{
int ret, pid;
if (pid > 0) {
if (job_count >= max_jobs) {
- jobs_pending++;
+ if (jobs_pending < max_jobs_pending)
+ jobs_pending++;
+ else
+ deny_job();
} else {
ret = grant_new_job();
return 0;
no_count_cpus:
pr_info("Set maximum number of parallel jobs to %d\n", max_jobs);
+ max_jobs_pending = max_jobs * 50 + 25;
+ pr_info("Set maximum number of pending jobs to %d\n", max_jobs_pending);
+
return 0;
}
if (ret < 0)
pr_err("Job control request failure: %m\n");
+ if (byte < 0) {
+ pr_info("Did not get permission to execute. Terminating\n");
+
+ /*
+ * Avoid running exit handler, that would tell the
+ * parent we died normally and decrement the job
+ * counters.
+ */
+ raise(SIGKILL);
+ }
+
pr_info("Continuing\n");
return child;
}