Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1536491 > unrolled thread

Re: [RFC v3 1/6] Track the active utilisation

Started byluca abeni <luca.abeni@unitn.it>
First post2016-12-05 23:40 +0100
Last post2016-12-06 15:10 +0100
Articles 4 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [RFC v3 1/6] Track the active utilisation luca abeni <luca.abeni@unitn.it> - 2016-12-05 23:40 +0100
    Re: [RFC v3 1/6] Track the active utilisation Peter Zijlstra <peterz@infradead.org> - 2016-12-06 09:40 +0100
      Re: [RFC v3 1/6] Track the active utilisation luca abeni <luca.abeni@unitn.it> - 2016-12-06 10:00 +0100
      Re: [RFC v3 1/6] Track the active utilisation luca abeni <luca.abeni@unitn.it> - 2016-12-06 15:10 +0100

#1536491 — Re: [RFC v3 1/6] Track the active utilisation

Fromluca abeni <luca.abeni@unitn.it>
Date2016-12-05 23:40 +0100
SubjectRe: [RFC v3 1/6] Track the active utilisation
Message-ID<sLa5s-244-23@gated-at.bofh.it>
Hi Peter,

On Fri, 18 Nov 2016 15:23:59 +0100
Peter Zijlstra <peterz@infradead.org> wrote:
[...]
> 	u64 running_bw;
> 
> static void add_running_bw(struct sched_dl_entity *dl_se, struct
> dl_rq *dl_rq) {
> 	u64 old = dl_rq->running_bw;
> 
> 	dl_rq->running_bw += dl_se->dl_bw;
> 	SCHED_WARN_ON(dl_rq->running_bw < old); /* overflow */
> }
> 
> static void sub_running_bw(struct sched_dl_entity *dl_se, struct
> dl_rq *dl_rq) {
> 	u64 old = dl_rq->running_bw;
> 
> 	dl_rq->running_bw -= dl_se->dl_bw;
> 	SCHED_WARN_ON(dl_rq->running_bw > old); /* underflow */
> }

I wanted to change "SCHED_WARN_ON(dl_rq->running_bw > old); /*
underflow */" into "if (SCHED_WARN_ON(...)) dl_rq->running_bw = 0" (to
avoid using nonsensical "running_bw" values), but I see that
"SCHED_WARN_ON()" cannot be used inside an if (this seems to be a
difference respect to "SCHED_WARN()").
This is because of the definition used when CONFIG_SCHED_DEBUG is not
defined (I noticed the issue when testing with random kernel
configurations).

Is this expected? If yes, what should I do in this case? Something like
	SCHED_WARN_ON(dl_rq->running_bw > old); /* underflow */
	if (dl_rq->running_bw > old)
		dl_rq->running_bw = 0;
?
Or something else?


			Thanks,
				Luca

[toc] | [next] | [standalone]


#1536765

FromPeter Zijlstra <peterz@infradead.org>
Date2016-12-06 09:40 +0100
Message-ID<sLjs5-87p-13@gated-at.bofh.it>
In reply to#1536491
On Mon, Dec 05, 2016 at 11:30:05PM +0100, luca abeni wrote:
> Hi Peter,
> 
> On Fri, 18 Nov 2016 15:23:59 +0100
> Peter Zijlstra <peterz@infradead.org> wrote:
> [...]
> > 	u64 running_bw;
> > 
> > static void add_running_bw(struct sched_dl_entity *dl_se, struct
> > dl_rq *dl_rq) {
> > 	u64 old = dl_rq->running_bw;
> > 
> > 	dl_rq->running_bw += dl_se->dl_bw;
> > 	SCHED_WARN_ON(dl_rq->running_bw < old); /* overflow */
> > }
> > 
> > static void sub_running_bw(struct sched_dl_entity *dl_se, struct
> > dl_rq *dl_rq) {
> > 	u64 old = dl_rq->running_bw;
> > 
> > 	dl_rq->running_bw -= dl_se->dl_bw;
> > 	SCHED_WARN_ON(dl_rq->running_bw > old); /* underflow */
> > }
> 
> I wanted to change "SCHED_WARN_ON(dl_rq->running_bw > old); /*
> underflow */" into "if (SCHED_WARN_ON(...)) dl_rq->running_bw = 0" (to
> avoid using nonsensical "running_bw" values), but I see that
> "SCHED_WARN_ON()" cannot be used inside an if (this seems to be a
> difference respect to "SCHED_WARN()").

There's a SCHED_WARN? Did you mean to say WARN_ON()?

And yes, mostly by accident I think, I'm not a big user of that pattern
and neglected it when I did SCHED_WARN_ON().

> This is because of the definition used when CONFIG_SCHED_DEBUG is not
> defined (I noticed the issue when testing with random kernel
> configurations).

I'm fine changing the definition, just find something that works. The
current ((void)(x)) thing was to avoid unused complaints -- although I'm
not sure there were any.

[toc] | [prev] | [next] | [standalone]


#1536784

Fromluca abeni <luca.abeni@unitn.it>
Date2016-12-06 10:00 +0100
Message-ID<sLjLr-8eg-7@gated-at.bofh.it>
In reply to#1536765
On Tue, 6 Dec 2016 09:35:01 +0100
Peter Zijlstra <peterz@infradead.org> wrote:

> On Mon, Dec 05, 2016 at 11:30:05PM +0100, luca abeni wrote:
> > Hi Peter,
> > 
> > On Fri, 18 Nov 2016 15:23:59 +0100
> > Peter Zijlstra <peterz@infradead.org> wrote:
> > [...]  
> > > 	u64 running_bw;
> > > 
> > > static void add_running_bw(struct sched_dl_entity *dl_se, struct
> > > dl_rq *dl_rq) {
> > > 	u64 old = dl_rq->running_bw;
> > > 
> > > 	dl_rq->running_bw += dl_se->dl_bw;
> > > 	SCHED_WARN_ON(dl_rq->running_bw < old); /* overflow */
> > > }
> > > 
> > > static void sub_running_bw(struct sched_dl_entity *dl_se, struct
> > > dl_rq *dl_rq) {
> > > 	u64 old = dl_rq->running_bw;
> > > 
> > > 	dl_rq->running_bw -= dl_se->dl_bw;
> > > 	SCHED_WARN_ON(dl_rq->running_bw > old); /* underflow */
> > > }  
> > 
> > I wanted to change "SCHED_WARN_ON(dl_rq->running_bw > old); /*
> > underflow */" into "if (SCHED_WARN_ON(...)) dl_rq->running_bw =
> > 0" (to avoid using nonsensical "running_bw" values), but I see that
> > "SCHED_WARN_ON()" cannot be used inside an if (this seems to be a
> > difference respect to "SCHED_WARN()").  
> 
> There's a SCHED_WARN? Did you mean to say WARN_ON()?

Sorry, I managed to confuse myself... I was thinking about WARN_ON()
(the one I used in the previous version of my patches).

> And yes, mostly by accident I think, I'm not a big user of that
> pattern and neglected it when I did SCHED_WARN_ON().

You mean the "if(WARN(...))" pattern? I think it was suggested in a
previous round of reviews.


> > This is because of the definition used when CONFIG_SCHED_DEBUG is
> > not defined (I noticed the issue when testing with random kernel
> > configurations).  
> 
> I'm fine changing the definition, just find something that works. The
> current ((void)(x)) thing was to avoid unused complaints -- although
> I'm not sure there were any.

Ok; I'll see if I manage to find a working definition.


			Thanks,
				Luca

[toc] | [prev] | [next] | [standalone]


#1536992

Fromluca abeni <luca.abeni@unitn.it>
Date2016-12-06 15:10 +0100
Message-ID<sLoBr-335-3@gated-at.bofh.it>
In reply to#1536765
Hi Peter,

On Tue, 6 Dec 2016 09:35:01 +0100
Peter Zijlstra <peterz@infradead.org> wrote:
[...]
> > This is because of the definition used when CONFIG_SCHED_DEBUG is
> > not defined (I noticed the issue when testing with random kernel
> > configurations).  
> 
> I'm fine changing the definition, just find something that works. The
> current ((void)(x)) thing was to avoid unused complaints -- although
> I'm not sure there were any.

Below is what I came up with... It fixes the build, and seems to work
fine generating no warnings (I tested with gcc 5.4.0). To write this
patch, I re-used some code from include/asm-generic/bug.h, that has no
copyright header, so I just added my signed-off-by (but I am not sure
if this is the correct way to go).


				Luca



From 74e67d61c4b98c2498880932b953c65e9653c121 Mon Sep 17 00:00:00 2001
From: Luca Abeni <luca.abeni@unitn.it>
Date: Tue, 6 Dec 2016 10:02:28 +0100
Subject: [PATCH 7/7] sched.h: Improve SCHED_WARN_ON() when CONFIG_SCHED_DEBUG is not defined

With the current definition of SCHED_WARN_ON(), something like
	if (SCHED_WARN_ON(condition)) ...
fails with
	error: void value not ignored as it ought to be
	 #define SCHED_WARN_ON(x) ((void)(x))
	                          ^

This patch fixes the issue by using the same code used in WARN_ON()

Signed-off-by: Luca Abeni <luca.abeni@unitn.it>
---
 kernel/sched/sched.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index ef4bdaa..2e96aa4 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -19,7 +19,10 @@
 #ifdef CONFIG_SCHED_DEBUG
 #define SCHED_WARN_ON(x)	WARN_ONCE(x, #x)
 #else
-#define SCHED_WARN_ON(x)	((void)(x))
+#define SCHED_WARN_ON(x)	({					\
+	int __ret_warn_on = !!(x);					\
+	unlikely(__ret_warn_on);					\
+})
 #endif
 
 struct rq;
-- 
2.7.4

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web