2019-07-09 06:03:51

by Alex Shi

[permalink] [raw]
Subject: [PATCH 1/2] cputime: remove rq parameter for function clean up

We could use the per cpu rq in function directly instead of pass it as
a parameter, that is more simple and could do further clean up.

Signed-off-by: Alex Shi <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Wanpeng Li <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: [email protected]
---
kernel/sched/cputime.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index 2305ce89a26c..3aaf761ede81 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -355,7 +355,7 @@ void thread_group_cputime(struct task_struct *tsk, struct task_cputime *times)
* softirq as those do not count in task exec_runtime any more.
*/
static void irqtime_account_process_tick(struct task_struct *p, int user_tick,
- struct rq *rq, int ticks)
+ int ticks)
{
u64 other, cputime = TICK_NSEC * ticks;

@@ -381,7 +381,7 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick,
account_system_index_time(p, cputime, CPUTIME_SOFTIRQ);
} else if (user_tick) {
account_user_time(p, cputime);
- } else if (p == rq->idle) {
+ } else if (p == this_rq()->idle) {
account_idle_time(cputime);
} else if (p->flags & PF_VCPU) { /* System time or guest time */
account_guest_time(p, cputime);
@@ -392,14 +392,12 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick,

static void irqtime_account_idle_ticks(int ticks)
{
- struct rq *rq = this_rq();
-
- irqtime_account_process_tick(current, 0, rq, ticks);
+ irqtime_account_process_tick(current, 0, ticks);
}
#else /* CONFIG_IRQ_TIME_ACCOUNTING */
static inline void irqtime_account_idle_ticks(int ticks) { }
static inline void irqtime_account_process_tick(struct task_struct *p, int user_tick,
- struct rq *rq, int nr_ticks) { }
+ int nr_ticks) { }
#endif /* CONFIG_IRQ_TIME_ACCOUNTING */

/*
@@ -475,13 +473,12 @@ void thread_group_cputime_adjusted(struct task_struct *p, u64 *ut, u64 *st)
void account_process_tick(struct task_struct *p, int user_tick)
{
u64 cputime, steal;
- struct rq *rq = this_rq();

if (vtime_accounting_cpu_enabled())
return;

if (sched_clock_irqtime) {
- irqtime_account_process_tick(p, user_tick, rq, 1);
+ irqtime_account_process_tick(p, user_tick, 1);
return;
}

@@ -495,7 +492,7 @@ void account_process_tick(struct task_struct *p, int user_tick)

if (user_tick)
account_user_time(p, cputime);
- else if ((p != rq->idle) || (irq_count() != HARDIRQ_OFFSET))
+ else if ((p != this_rq()->idle) || (irq_count() != HARDIRQ_OFFSET))
account_system_time(p, HARDIRQ_OFFSET, cputime);
else
account_idle_time(cputime);
--
2.19.1.856.g8858448bb


2019-07-09 06:03:51

by Alex Shi

[permalink] [raw]
Subject: [PATCH 2/2] cputime: remove duplicate code in account_process_tick

In funcation account_process_tick, func actually do same things with
irqtime_account_process_tick, whenever if IRQ_TIME_ACCOUNTING set or
if sched_clock_irqtime enabled.

So it's better to reuse one function for both.

Signed-off-by: Alex Shi <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Wanpeng Li <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: [email protected]
---
kernel/sched/cputime.c | 26 ++------------------------
1 file changed, 2 insertions(+), 24 deletions(-)

diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index 3aaf761ede81..6116f50e1f37 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -332,7 +332,6 @@ void thread_group_cputime(struct task_struct *tsk, struct task_cputime *times)
rcu_read_unlock();
}

-#ifdef CONFIG_IRQ_TIME_ACCOUNTING
/*
* Account a tick to a process and cpustat
* @p: the process that the CPU time gets accounted to
@@ -390,14 +389,13 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick,
}
}

+#ifdef CONFIG_IRQ_TIME_ACCOUNTING
static void irqtime_account_idle_ticks(int ticks)
{
irqtime_account_process_tick(current, 0, ticks);
}
#else /* CONFIG_IRQ_TIME_ACCOUNTING */
static inline void irqtime_account_idle_ticks(int ticks) { }
-static inline void irqtime_account_process_tick(struct task_struct *p, int user_tick,
- int nr_ticks) { }
#endif /* CONFIG_IRQ_TIME_ACCOUNTING */

/*
@@ -472,30 +470,10 @@ void thread_group_cputime_adjusted(struct task_struct *p, u64 *ut, u64 *st)
*/
void account_process_tick(struct task_struct *p, int user_tick)
{
- u64 cputime, steal;
-
if (vtime_accounting_cpu_enabled())
return;

- if (sched_clock_irqtime) {
- irqtime_account_process_tick(p, user_tick, 1);
- return;
- }
-
- cputime = TICK_NSEC;
- steal = steal_account_process_time(ULONG_MAX);
-
- if (steal >= cputime)
- return;
-
- cputime -= steal;
-
- if (user_tick)
- account_user_time(p, cputime);
- else if ((p != this_rq()->idle) || (irq_count() != HARDIRQ_OFFSET))
- account_system_time(p, HARDIRQ_OFFSET, cputime);
- else
- account_idle_time(cputime);
+ irqtime_account_process_tick(p, user_tick, 1);
}

/*
--
2.19.1.856.g8858448bb

2019-07-10 14:39:01

by Peter Zijlstra

[permalink] [raw]
Subject: Re: [PATCH 2/2] cputime: remove duplicate code in account_process_tick

On Tue, Jul 09, 2019 at 02:01:00PM +0800, Alex Shi wrote:
> In funcation account_process_tick, func actually do same things with
> irqtime_account_process_tick, whenever if IRQ_TIME_ACCOUNTING set or
> if sched_clock_irqtime enabled.
>
> So it's better to reuse one function for both.

But it's not the exact same.. and you didn't say, not did you say why
that is fine.

2019-07-11 07:17:59

by Alex Shi

[permalink] [raw]
Subject: Re: [PATCH 2/2] cputime: remove duplicate code in account_process_tick



?? 2019/7/10 ????10:15, Peter Zijlstra ะด??:
> On Tue, Jul 09, 2019 at 02:01:00PM +0800, Alex Shi wrote:
>> In funcation account_process_tick, func actually do same things with
>> irqtime_account_process_tick, whenever if IRQ_TIME_ACCOUNTING set or
>> if sched_clock_irqtime enabled.
>>
>> So it's better to reuse one function for both.
>
> But it's not the exact same.. and you didn't say, not did you say why
> that is fine.
>

Thanks for reply!

The irqtime_account_process_tick path was introduced for precise ns irq time account(abb74cefa9c682fb sched: Export ns irqtimes through /proc/stat) while account_process_tick still use jiffes. but now both pathes are using ns cputime. And there is not strong reason to keep 2 very very similar path coexists. That's the reason I believe unite the collection is better.

Thanks
Alex