Skip to content

Commit 9667a23

Browse files
KAGA-KOKOjohnstultz-work
authored andcommitted
delayacct: Make accounting nanosecond based
Kill the timespec juggling and calculate with plain nanoseconds. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: John Stultz <john.stultz@linaro.org>
1 parent ccbf62d commit 9667a23

2 files changed

Lines changed: 14 additions & 24 deletions

File tree

‎include/linux/sched.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -813,15 +813,15 @@ struct task_delay_info {
813813
* associated with the operation is added to XXX_delay.
814814
* XXX_delay contains the accumulated delay time in nanoseconds.
815815
*/
816-
struct timespec blkio_start, blkio_end; /* Shared by blkio, swapin */
816+
u64 blkio_start; /* Shared by blkio, swapin */
817817
u64 blkio_delay; /* wait for sync block io completion */
818818
u64 swapin_delay; /* wait for swapin block io completion */
819819
u32 blkio_count; /* total count of the number of sync block */
820820
/* io operations performed */
821821
u32 swapin_count; /* total count of the number of swapin block */
822822
/* io operations performed */
823823

824-
struct timespec freepages_start, freepages_end;
824+
u64 freepages_start;
825825
u64 freepages_delay; /* wait for memory reclaim */
826826
u32 freepages_count; /* total count of memory reclaim */
827827
};

‎kernel/delayacct.c‎

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -46,45 +46,36 @@ void __delayacct_tsk_init(struct task_struct *tsk)
4646
}
4747

4848
/*
49-
* Finish delay accounting for a statistic using
50-
* its timestamps (@start, @end), accumalator (@total) and @count
49+
* Finish delay accounting for a statistic using its timestamps (@start),
50+
* accumalator (@total) and @count
5151
*/
52-
53-
static void delayacct_end(struct timespec *start, struct timespec *end,
54-
u64 *total, u32 *count)
52+
static void delayacct_end(u64 *start, u64 *total, u32 *count)
5553
{
56-
struct timespec ts;
57-
s64 ns;
54+
s64 ns = ktime_get_ns() - *start;
5855
unsigned long flags;
5956

60-
ktime_get_ts(end);
61-
ts = timespec_sub(*end, *start);
62-
ns = timespec_to_ns(&ts);
63-
if (ns < 0)
64-
return;
65-
66-
spin_lock_irqsave(&current->delays->lock, flags);
67-
*total += ns;
68-
(*count)++;
69-
spin_unlock_irqrestore(&current->delays->lock, flags);
57+
if (ns > 0) {
58+
spin_lock_irqsave(&current->delays->lock, flags);
59+
*total += ns;
60+
(*count)++;
61+
spin_unlock_irqrestore(&current->delays->lock, flags);
62+
}
7063
}
7164

7265
void __delayacct_blkio_start(void)
7366
{
74-
ktime_get_ts(&current->delays->blkio_start);
67+
current->delays->blkio_start = ktime_get_ns();
7568
}
7669

7770
void __delayacct_blkio_end(void)
7871
{
7972
if (current->delays->flags & DELAYACCT_PF_SWAPIN)
8073
/* Swapin block I/O */
8174
delayacct_end(&current->delays->blkio_start,
82-
&current->delays->blkio_end,
8375
&current->delays->swapin_delay,
8476
&current->delays->swapin_count);
8577
else /* Other block I/O */
8678
delayacct_end(&current->delays->blkio_start,
87-
&current->delays->blkio_end,
8879
&current->delays->blkio_delay,
8980
&current->delays->blkio_count);
9081
}
@@ -159,13 +150,12 @@ __u64 __delayacct_blkio_ticks(struct task_struct *tsk)
159150

160151
void __delayacct_freepages_start(void)
161152
{
162-
ktime_get_ts(&current->delays->freepages_start);
153+
current->delays->freepages_start = ktime_get_ns();
163154
}
164155

165156
void __delayacct_freepages_end(void)
166157
{
167158
delayacct_end(&current->delays->freepages_start,
168-
&current->delays->freepages_end,
169159
&current->delays->freepages_delay,
170160
&current->delays->freepages_count);
171161
}

0 commit comments

Comments
 (0)