Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1322783
| From | riel@redhat.com |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 1/4] sched,time: remove non-power-of-two divides from __acct_update_integrals |
| Date | 2016-02-01 03:20 +0100 |
| Message-ID | <qXcfU-45K-9@gated-at.bofh.it> (permalink) |
| References | <qXcfT-45K-3@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
From: Rik van Riel <riel@redhat.com>
When running a microbenchmark calling an invalid syscall number
in a loop, on a nohz_full CPU, we spend a full 9% of our CPU
time in __acct_update_integrals.
This function converts cputime_t to jiffies, to a timeval, only to
convert the timeval back to microseconds before discarding it.
This patch leaves __acct_update_integrals functionally equivalent,
but speeds things up by about 12%, with 10 million calls to an
invalid syscall number dropping from 3.7 to 3.25 seconds.
Signed-off-by: Rik van Riel <riel@redhat.com>
---
kernel/tsacct.c | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)
diff --git a/kernel/tsacct.c b/kernel/tsacct.c
index 975cb49e32bf..1b121a2f1c55 100644
--- a/kernel/tsacct.c
+++ b/kernel/tsacct.c
@@ -93,9 +93,9 @@ void xacct_add_tsk(struct taskstats *stats, struct task_struct *p)
{
struct mm_struct *mm;
- /* convert pages-usec to Mbyte-usec */
- stats->coremem = p->acct_rss_mem1 * PAGE_SIZE / MB;
- stats->virtmem = p->acct_vm_mem1 * PAGE_SIZE / MB;
+ /* convert pages-nsec/1024 to Mbyte-usec, see __acct_update_integrals */
+ stats->coremem = p->acct_rss_mem1 * PAGE_SIZE / (1000 * KB);
+ stats->virtmem = p->acct_vm_mem1 * PAGE_SIZE / (1000 * KB);
mm = get_task_mm(p);
if (mm) {
/* adjust to KB unit */
@@ -125,22 +125,26 @@ static void __acct_update_integrals(struct task_struct *tsk,
{
if (likely(tsk->mm)) {
cputime_t time, dtime;
- struct timeval value;
unsigned long flags;
u64 delta;
local_irq_save(flags);
time = stime + utime;
dtime = time - tsk->acct_timexpd;
- jiffies_to_timeval(cputime_to_jiffies(dtime), &value);
- delta = value.tv_sec;
- delta = delta * USEC_PER_SEC + value.tv_usec;
+ /* Avoid division: cputime_t is often in nanoseconds already. */
+ delta = cputime_to_nsecs(dtime);
- if (delta == 0)
+ if (delta < TICK_NSEC)
goto out;
+
tsk->acct_timexpd = time;
- tsk->acct_rss_mem1 += delta * get_mm_rss(tsk->mm);
- tsk->acct_vm_mem1 += delta * tsk->mm->total_vm;
+ /*
+ * Divide by 1024 to avoid overflow, and to avoid division.
+ * The final unit reported to userspace is Mbyte-usecs,
+ * the rest of the math is done in xacct_add_tsk.
+ */
+ tsk->acct_rss_mem1 += delta * get_mm_rss(tsk->mm) >> 10;
+ tsk->acct_vm_mem1 += delta * tsk->mm->total_vm >> 10;
out:
local_irq_restore(flags);
}
--
2.5.0
Back to linux.kernel | Previous | Next — Next in thread | Find similar | Unroll thread
[PATCH 1/4] sched,time: remove non-power-of-two divides from __acct_update_integrals riel@redhat.com - 2016-02-01 03:20 +0100
Re: [PATCH 1/4] sched,time: remove non-power-of-two divides from __acct_update_integrals kbuild test robot <lkp@intel.com> - 2016-02-01 05:50 +0100
Re: [PATCH 1/4] sched,time: remove non-power-of-two divides from __acct_update_integrals Thomas Gleixner <tglx@linutronix.de> - 2016-02-01 09:40 +0100
Re: [PATCH 1/4] sched,time: remove non-power-of-two divides from __acct_update_integrals Peter Zijlstra <peterz@infradead.org> - 2016-02-01 10:30 +0100
Re: [PATCH 1/4] sched,time: remove non-power-of-two divides from __acct_update_integrals Thomas Gleixner <tglx@linutronix.de> - 2016-02-01 10:40 +0100
Re: [PATCH 1/4] sched,time: remove non-power-of-two divides from __acct_update_integrals Rik van Riel <riel@redhat.com> - 2016-02-01 14:50 +0100
Re: [PATCH 1/4] sched,time: remove non-power-of-two divides from __acct_update_integrals Peter Zijlstra <peterz@infradead.org> - 2016-02-01 15:00 +0100
csiph-web