public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH][3/4] sched: add above background load function
@ 2006-03-13  8:07 Con Kolivas
  2006-03-13  9:07 ` Ingo Molnar
  2006-03-13 23:14 ` Peter Williams
  0 siblings, 2 replies; 4+ messages in thread
From: Con Kolivas @ 2006-03-13  8:07 UTC (permalink / raw)
  To: linux list; +Cc: Andrew Morton, Ingo Molnar, Peter Williams, ck list

Add an above_background_load() function which can be used by other subsystems
to detect if there is anything besides niced tasks running. Place it in
sched.h to allow it to be compiled out if not used.

Signed-off-by: Con Kolivas <kernel@kolivas.org>

---
 include/linux/sched.h |   16 ++++++++++++++++
 1 files changed, 16 insertions(+)

Index: linux-2.6.16-rc6-mm1/include/linux/sched.h
===================================================================
--- linux-2.6.16-rc6-mm1.orig/include/linux/sched.h	2006-03-13 17:05:14.000000000 +1100
+++ linux-2.6.16-rc6-mm1/include/linux/sched.h	2006-03-13 17:24:18.000000000 +1100
@@ -638,6 +638,22 @@ extern unsigned int max_cache_size;
 
 #endif	/* CONFIG_SMP */
 
+/*
+ * A runqueue laden with a single nice 0 task scores a weighted_cpuload of
+ * SCHED_LOAD_SCALE. This function returns 1 if any cpu is laden with a
+ * task of nice 0 or enough lower priority tasks to bring up the
+ * weighted_cpuload
+ */
+static inline int above_background_load(void)
+{
+	unsigned long cpu;
+
+	for_each_online_cpu(cpu) {
+		if (weighted_cpuload(cpu) >= SCHED_LOAD_SCALE)
+			return 1;
+	}
+	return 0;
+}
 
 struct io_context;			/* See blkdev.h */
 void exit_io_context(void);

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH][3/4] sched: add above background load function
  2006-03-13  8:07 [PATCH][3/4] sched: add above background load function Con Kolivas
@ 2006-03-13  9:07 ` Ingo Molnar
  2006-03-13 23:14 ` Peter Williams
  1 sibling, 0 replies; 4+ messages in thread
From: Ingo Molnar @ 2006-03-13  9:07 UTC (permalink / raw)
  To: Con Kolivas; +Cc: linux list, Andrew Morton, Peter Williams, ck list


* Con Kolivas <kernel@kolivas.org> wrote:

> Add an above_background_load() function which can be used by other 
> subsystems to detect if there is anything besides niced tasks running. 
> Place it in sched.h to allow it to be compiled out if not used.
> 
> Signed-off-by: Con Kolivas <kernel@kolivas.org>

Acked-by: Ingo Molnar <mingo@elte.hu>

	Ingo

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH][3/4] sched: add above background load function
  2006-03-13  8:07 [PATCH][3/4] sched: add above background load function Con Kolivas
  2006-03-13  9:07 ` Ingo Molnar
@ 2006-03-13 23:14 ` Peter Williams
  2006-03-13 23:38   ` Con Kolivas
  1 sibling, 1 reply; 4+ messages in thread
From: Peter Williams @ 2006-03-13 23:14 UTC (permalink / raw)
  To: Con Kolivas; +Cc: linux list, Andrew Morton, Ingo Molnar, ck list

Con Kolivas wrote:
> Add an above_background_load() function which can be used by other subsystems
> to detect if there is anything besides niced tasks running. Place it in
> sched.h to allow it to be compiled out if not used.
> 
> Signed-off-by: Con Kolivas <kernel@kolivas.org>
> 
> ---
>  include/linux/sched.h |   16 ++++++++++++++++
>  1 files changed, 16 insertions(+)
> 
> Index: linux-2.6.16-rc6-mm1/include/linux/sched.h
> ===================================================================
> --- linux-2.6.16-rc6-mm1.orig/include/linux/sched.h	2006-03-13 17:05:14.000000000 +1100
> +++ linux-2.6.16-rc6-mm1/include/linux/sched.h	2006-03-13 17:24:18.000000000 +1100
> @@ -638,6 +638,22 @@ extern unsigned int max_cache_size;
>  
>  #endif	/* CONFIG_SMP */
>  
> +/*
> + * A runqueue laden with a single nice 0 task scores a weighted_cpuload of
> + * SCHED_LOAD_SCALE. This function returns 1 if any cpu is laden with a
> + * task of nice 0 or enough lower priority tasks to bring up the
> + * weighted_cpuload
> + */
> +static inline int above_background_load(void)
> +{
> +	unsigned long cpu;
> +
> +	for_each_online_cpu(cpu) {
> +		if (weighted_cpuload(cpu) >= SCHED_LOAD_SCALE)
> +			return 1;
> +	}
> +	return 0;
> +}
>  
>  struct io_context;			/* See blkdev.h */
>  void exit_io_context(void);

I think that you may need to take into account the contribution to the 
load by your swap prefetching thread when it calls this function 
otherwise it could cause an incorrect (from your point of view) positive 
return value.  If the thread has a positive nice value this comment can 
probably be ignored.

If not, then the adjustment could be made by subtracting the threads 
load_weight from the weighted_cpuload() when looking at the CPU the 
thread is running on.  To minimize the effect on the overhead of the 
function this refinement could be only performed when the current if 
statement succeeds e.g. something like

if (weighted_cpuload(cpu) >= SCHED_LOAD_SCALE) {
	if (smp_processor_id() != cpu || (weighted_cpuload(cpu) - 
current->load_weight) >= SCHED_LOAD_SCALE)
		return 1;
}

Peter
-- 
Peter Williams                                   pwil3058@bigpond.net.au

"Learning, n. The kind of ignorance distinguishing the studious."
  -- Ambrose Bierce

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH][3/4] sched: add above background load function
  2006-03-13 23:14 ` Peter Williams
@ 2006-03-13 23:38   ` Con Kolivas
  0 siblings, 0 replies; 4+ messages in thread
From: Con Kolivas @ 2006-03-13 23:38 UTC (permalink / raw)
  To: Peter Williams; +Cc: linux list, Andrew Morton, Ingo Molnar, ck list

[-- Attachment #1: Type: text/plain, Size: 474 bytes --]

Peter Williams writes:

> Con Kolivas wrote:
>> +		if (weighted_cpuload(cpu) >= SCHED_LOAD_SCALE)
>> +			return 1;
> I think that you may need to take into account the contribution to the 
> load by your swap prefetching thread when it calls this function 
> otherwise it could cause an incorrect (from your point of view) positive 
> return value.  If the thread has a positive nice value this comment can 
> probably be ignored.

kprefetchd runs at nice 19.

Cheers,
Con


[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-03-13 23:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-03-13  8:07 [PATCH][3/4] sched: add above background load function Con Kolivas
2006-03-13  9:07 ` Ingo Molnar
2006-03-13 23:14 ` Peter Williams
2006-03-13 23:38   ` Con Kolivas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox