All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sched/fair: Remove max_vruntime() and min_vruntime()
@ 2022-10-27  1:53 Yajun Deng
  2022-10-27  7:54 ` Peter Zijlstra
  0 siblings, 1 reply; 4+ messages in thread
From: Yajun Deng @ 2022-10-27  1:53 UTC (permalink / raw)
  To: mingo, peterz, juri.lelli, vincent.guittot, dietmar.eggemann,
	rostedt, bsegall, mgorman, bristot, vschneid
  Cc: linux-kernel, Yajun Deng

There is no need to write max_vruntime() and min_vruntime() functions,
we can use max_t() and min_t() instead.

Signed-off-by: Yajun Deng <yajun.deng@linux.dev>
---
 kernel/sched/fair.c | 24 +++---------------------
 1 file changed, 3 insertions(+), 21 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index e4a0b8bd941c..bba8e0c43d59 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -562,24 +562,6 @@ void account_cfs_rq_runtime(struct cfs_rq *cfs_rq, u64 delta_exec);
  * Scheduling class tree data structure manipulation methods:
  */
 
-static inline u64 max_vruntime(u64 max_vruntime, u64 vruntime)
-{
-	s64 delta = (s64)(vruntime - max_vruntime);
-	if (delta > 0)
-		max_vruntime = vruntime;
-
-	return max_vruntime;
-}
-
-static inline u64 min_vruntime(u64 min_vruntime, u64 vruntime)
-{
-	s64 delta = (s64)(vruntime - min_vruntime);
-	if (delta < 0)
-		min_vruntime = vruntime;
-
-	return min_vruntime;
-}
-
 static inline bool entity_before(struct sched_entity *a,
 				struct sched_entity *b)
 {
@@ -609,12 +591,12 @@ static void update_min_vruntime(struct cfs_rq *cfs_rq)
 		if (!curr)
 			vruntime = se->vruntime;
 		else
-			vruntime = min_vruntime(vruntime, se->vruntime);
+			vruntime = min_t(u64, vruntime, se->vruntime);
 	}
 
 	/* ensure we never gain time by being placed backwards. */
 	u64_u32_store(cfs_rq->min_vruntime,
-		      max_vruntime(cfs_rq->min_vruntime, vruntime));
+		      max_t(u64, cfs_rq->min_vruntime, vruntime));
 }
 
 static inline bool __entity_less(struct rb_node *a, const struct rb_node *b)
@@ -4543,7 +4525,7 @@ place_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int initial)
 	}
 
 	/* ensure we never gain time by being placed backwards. */
-	se->vruntime = max_vruntime(se->vruntime, vruntime);
+	se->vruntime = max_t(u64, se->vruntime, vruntime);
 }
 
 static void check_enqueue_throttle(struct cfs_rq *cfs_rq);
-- 
2.25.1


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

* Re: [PATCH] sched/fair: Remove max_vruntime() and min_vruntime()
  2022-10-27  1:53 [PATCH] sched/fair: Remove max_vruntime() and min_vruntime() Yajun Deng
@ 2022-10-27  7:54 ` Peter Zijlstra
  2022-10-27  7:55   ` Peter Zijlstra
  2022-10-27  8:01   ` Yajun Deng
  0 siblings, 2 replies; 4+ messages in thread
From: Peter Zijlstra @ 2022-10-27  7:54 UTC (permalink / raw)
  To: Yajun Deng
  Cc: mingo, juri.lelli, vincent.guittot, dietmar.eggemann, rostedt,
	bsegall, mgorman, bristot, vschneid, linux-kernel

On Thu, Oct 27, 2022 at 09:53:51AM +0800, Yajun Deng wrote:
> There is no need to write max_vruntime() and min_vruntime() functions,
> we can use max_t() and min_t() instead.

Here; I did your homework for you:

/* max.c */
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>

typedef unsigned long long u64;
typedef unsigned long long s64;

static u64 max_vruntime(u64 max_vruntime, u64 vruntime)
{
	s64 delta = (s64)(vruntime - max_vruntime);
	if (delta > 0)
		max_vruntime = vruntime;
	return max_vruntime;
}

static u64 max(u64 a, u64 b)
{
	return a > b ? a : b;
}

int main(int argc, char **argv)
{
	u64 a, b;

	if (argc < 3)
		return 0;

	a = strtoll(argv[1], NULL, 10);
	b = strtoll(argv[2], NULL, 10);
	printf("         max(%lu, %lu) = %lu\n", a, b, max(a,b));
	printf("max_vruntime(%lu, %lu) = %lu\n", a, b, max_vruntime(a,b));

	return 0;
}

$ ./max -1 0
         max(18446744073709551615, 0) = 18446744073709551615
max_vruntime(18446744073709551615, 0) = 0

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

* Re: [PATCH] sched/fair: Remove max_vruntime() and min_vruntime()
  2022-10-27  7:54 ` Peter Zijlstra
@ 2022-10-27  7:55   ` Peter Zijlstra
  2022-10-27  8:01   ` Yajun Deng
  1 sibling, 0 replies; 4+ messages in thread
From: Peter Zijlstra @ 2022-10-27  7:55 UTC (permalink / raw)
  To: Yajun Deng
  Cc: mingo, juri.lelli, vincent.guittot, dietmar.eggemann, rostedt,
	bsegall, mgorman, bristot, vschneid, linux-kernel

On Thu, Oct 27, 2022 at 09:54:09AM +0200, Peter Zijlstra wrote:
> On Thu, Oct 27, 2022 at 09:53:51AM +0800, Yajun Deng wrote:
> > There is no need to write max_vruntime() and min_vruntime() functions,
> > we can use max_t() and min_t() instead.
> 
> Here; I did your homework for you:
> 
> /* max.c */
> #include <stdio.h>
> #include <stdint.h>
> #include <stdlib.h>
> 
> typedef unsigned long long u64;
> typedef unsigned long long s64;

This should obviously be just 'long long', but the result doesn't
change.

/me goes goes get more wake-up juice.

> 
> static u64 max_vruntime(u64 max_vruntime, u64 vruntime)
> {
> 	s64 delta = (s64)(vruntime - max_vruntime);
> 	if (delta > 0)
> 		max_vruntime = vruntime;
> 	return max_vruntime;
> }
> 
> static u64 max(u64 a, u64 b)
> {
> 	return a > b ? a : b;
> }
> 
> int main(int argc, char **argv)
> {
> 	u64 a, b;
> 
> 	if (argc < 3)
> 		return 0;
> 
> 	a = strtoll(argv[1], NULL, 10);
> 	b = strtoll(argv[2], NULL, 10);
> 	printf("         max(%lu, %lu) = %lu\n", a, b, max(a,b));
> 	printf("max_vruntime(%lu, %lu) = %lu\n", a, b, max_vruntime(a,b));
> 
> 	return 0;
> }
> 
> $ ./max -1 0
>          max(18446744073709551615, 0) = 18446744073709551615
> max_vruntime(18446744073709551615, 0) = 0

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

* Re: [PATCH] sched/fair: Remove max_vruntime() and min_vruntime()
  2022-10-27  7:54 ` Peter Zijlstra
  2022-10-27  7:55   ` Peter Zijlstra
@ 2022-10-27  8:01   ` Yajun Deng
  1 sibling, 0 replies; 4+ messages in thread
From: Yajun Deng @ 2022-10-27  8:01 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: mingo, juri.lelli, vincent.guittot, dietmar.eggemann, rostedt,
	bsegall, mgorman, bristot, vschneid, linux-kernel

October 27, 2022 3:55 PM, "Peter Zijlstra" <peterz@infradead.org> wrote:

> On Thu, Oct 27, 2022 at 09:54:09AM +0200, Peter Zijlstra wrote:
> 
>> On Thu, Oct 27, 2022 at 09:53:51AM +0800, Yajun Deng wrote:
>> There is no need to write max_vruntime() and min_vruntime() functions,
>> we can use max_t() and min_t() instead.
>> 
>> Here; I did your homework for you:
>> 

Thanks for your guidance.

>> /* max.c */
>> #include <stdio.h>
>> #include <stdint.h>
>> #include <stdlib.h>
>> 
>> typedef unsigned long long u64;
>> typedef unsigned long long s64;
> 
> This should obviously be just 'long long', but the result doesn't
> change.
> 
> /me goes goes get more wake-up juice.
> 
>> static u64 max_vruntime(u64 max_vruntime, u64 vruntime)
>> {
>> s64 delta = (s64)(vruntime - max_vruntime);
>> if (delta > 0)
>> max_vruntime = vruntime;
>> return max_vruntime;
>> }
>> 
>> static u64 max(u64 a, u64 b)
>> {
>> return a > b ? a : b;
>> }
>> 
>> int main(int argc, char **argv)
>> {
>> u64 a, b;
>> 
>> if (argc < 3)
>> return 0;
>> 
>> a = strtoll(argv[1], NULL, 10);
>> b = strtoll(argv[2], NULL, 10);
>> printf(" max(%lu, %lu) = %lu\n", a, b, max(a,b));
>> printf("max_vruntime(%lu, %lu) = %lu\n", a, b, max_vruntime(a,b));
>> 
>> return 0;
>> }
>> 
>> $ ./max -1 0
>> max(18446744073709551615, 0) = 18446744073709551615
>> max_vruntime(18446744073709551615, 0) = 0

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

end of thread, other threads:[~2022-10-27  8:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-27  1:53 [PATCH] sched/fair: Remove max_vruntime() and min_vruntime() Yajun Deng
2022-10-27  7:54 ` Peter Zijlstra
2022-10-27  7:55   ` Peter Zijlstra
2022-10-27  8:01   ` Yajun Deng

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.