Skip to contentSkip to conversation

Setup

PATCH In review Balbir Singh 3 participants 12 messages May 2, 2006 – May 10, 2006

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

PATCH 1/8 Setup

Changelog

Fixes comments by akpm
- unnecessary initialization of delayacct_on
- use kmem_cache_zalloc
- redundant check in __delayacct_tsk_exit

Other changes
- do not mix tabs and spaces

delayacct-setup.patch

Initialization code related to collection of per-task "delay" statistics which measure how long it had to wait for cpu, sync block io, swapping etc. The collection of statistics and the interface are in other patches. This patch sets up the data structures and allows the statistics collection to be disabled through a kernel boot paramater.

---

 Documentation/kernel-parameters.txt |    2 
 include/linux/delayacct.h           |   69 ++++++++++++++++++++++++++++
 include/linux/sched.h               |   20 ++++++++
 include/linux/time.h                |   10 ++++
 init/Kconfig                        |   10 ++++
 init/main.c                         |    2 
 kernel/Makefile                     |    1 
 kernel/delayacct.c                  |   87 ++++++++++++++++++++++++++++++++++++
 kernel/exit.c                       |    2 
 kernel/fork.c                       |    2 
 10 files changed, 205 insertions(+)
Documentation/kernel-parameters.txt renamed from Documentation/kernel-parameters.txt~delayacct-setup +2 -0
diff -puN Documentation/kernel-parameters.txt~delayacct-setup Documentation/kernel-parameters.txt
@@ -430,6 +430,8 @@ running once the system is up.
 			Format: <area>[,<node>]
 			See also Documentation/networking/decnet.txt.
 
+	delayacct	[KNL] Enable per-task delay accounting
+
 	devfs=		[DEVFS]
 			See Documentation/filesystems/devfs/boot-options.
 
include/linux/delayacct.h new file +69 -0

69 lines not on this page · raw message

include/linux/sched.h renamed from include/linux/sched.h~delayacct-setup +20 -0
diff -puN include/linux/sched.h~delayacct-setup include/linux/sched.h
@@ -536,6 +536,23 @@ struct sched_info {
 extern struct file_operations proc_schedstat_operations;
 #endif
 
+#ifdef CONFIG_TASK_DELAY_ACCT
+struct task_delay_info {
+	spinlock_t	lock;
+	unsigned int	flags;	/* Private per-task flags */
+
+	/* For each stat XXX, add following, aligned appropriately
+	 *
+	 * struct timespec XXX_start, XXX_end;
+	 * u64 XXX_delay;
+	 * u32 XXX_count;
+	 *
+	 * Atomicity of updates to XXX_delay, XXX_count protected by
+	 * single lock above (split into XXX_lock if contention is an issue).
+	 */
+};
+#endif
+
 enum idle_type
 {
 	SCHED_IDLE,
@@ -888,6 +905,9 @@ struct task_struct {
 	 * cache last used pipe for splice
 	 */
 	struct pipe_inode_info *splice_pipe;
+#ifdef	CONFIG_TASK_DELAY_ACCT
+	struct task_delay_info *delays;
+#endif
 };
 
 static inline pid_t process_group(struct task_struct *tsk)
include/linux/time.h renamed from include/linux/time.h~delayacct-setup +10 -0
diff -puN include/linux/time.h~delayacct-setup include/linux/time.h
@@ -68,6 +68,16 @@ extern unsigned long mktime(const unsign
 extern void set_normalized_timespec(struct timespec *ts, time_t sec, long nsec);
 
 /*
+ * sub = end - start, in normalized form
+ */
+static inline void timespec_sub(struct timespec *start, struct timespec *end,
+				struct timespec *sub)
+{
+	set_normalized_timespec(sub, end->tv_sec - start->tv_sec,
+				end->tv_nsec - start->tv_nsec);
+}
+
+/*
  * Returns true if the timespec is norm, false if denorm:
  */
 #define timespec_valid(ts) \
init/Kconfig renamed from init/Kconfig~delayacct-setup +10 -0
diff -puN init/Kconfig~delayacct-setup init/Kconfig
@@ -150,6 +150,16 @@ config BSD_PROCESS_ACCT_V3
 	  for processing it. A preliminary version of these tools is available
 	  at <http://www.physik3.uni-rostock.de/tim/kernel/utils/acct/>.
 
+config TASK_DELAY_ACCT
+	bool "Enable per-task delay accounting (EXPERIMENTAL)"
+	help
+	  Collect information on time spent by a task waiting for system
+	  resources like cpu, synchronous block I/O completion and swapping
+	  in pages. Such statistics can help in setting a task's priorities
+	  relative to other tasks for cpu, io, rss limits etc.
+
+	  Say N if unsure.
+
 config SYSCTL
 	bool "Sysctl support"
 	---help---
init/main.c renamed from init/main.c~delayacct-setup +2 -0
diff -puN init/main.c~delayacct-setup init/main.c
@@ -47,6 +47,7 @@
 #include <linux/rmap.h>
 #include <linux/mempolicy.h>
 #include <linux/key.h>
+#include <linux/delayacct.h>
 
 #include <asm/io.h>
 #include <asm/bugs.h>
@@ -541,6 +542,7 @@ asmlinkage void __init start_kernel(void
 	proc_root_init();
 #endif
 	cpuset_init();
+	delayacct_init();
 
 	check_bugs();
 
kernel/delayacct.c new file +87 -0

87 lines not on this page · raw message

kernel/exit.c renamed from kernel/exit.c~delayacct-setup +2 -0
diff -puN kernel/exit.c~delayacct-setup kernel/exit.c
@@ -35,6 +35,7 @@
 #include <linux/futex.h>
 #include <linux/compat.h>
 #include <linux/pipe_fs_i.h>
+#include <linux/delayacct.h>
 
 #include <asm/uaccess.h>
 #include <asm/unistd.h>
@@ -910,6 +911,7 @@ fastcall NORET_TYPE void do_exit(long co
 	if (unlikely(tsk->compat_robust_list))
 		compat_exit_robust_list(tsk);
 #endif
+	delayacct_tsk_exit(tsk);
 	exit_mm(tsk);
 
 	exit_sem(tsk);
kernel/fork.c renamed from kernel/fork.c~delayacct-setup +2 -0
diff -puN kernel/fork.c~delayacct-setup kernel/fork.c
@@ -44,6 +44,7 @@
 #include <linux/rmap.h>
 #include <linux/acct.h>
 #include <linux/cn_proc.h>
+#include <linux/delayacct.h>
 
 #include <asm/pgtable.h>
 #include <asm/pgalloc.h>
@@ -984,6 +985,7 @@ static task_t *copy_process(unsigned lon
 		goto bad_fork_cleanup_put_domain;
 
 	p->did_exec = 0;
+	delayacct_tsk_init(p);	/* Must remain after dup_task_struct() */
 	copy_flags(clone_flags, p);
 	p->pid = pid;
 	retval = -EFAULT;
kernel/Makefile renamed from kernel/Makefile~delayacct-setup +1 -0
diff -puN kernel/Makefile~delayacct-setup kernel/Makefile
@@ -38,6 +38,7 @@ obj-$(CONFIG_GENERIC_HARDIRQS) += irq/
 obj-$(CONFIG_SECCOMP) += seccomp.o
 obj-$(CONFIG_RCU_TORTURE_TEST) += rcutorture.o
 obj-$(CONFIG_RELAY) += relay.o
+obj-$(CONFIG_TASK_DELAY_ACCT) += delayacct.o
 
 ifneq ($(CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER),y)
 # According to Alan Modra <[email protected]>, the -fno-omit-frame-pointer is

_

#1 lore raw

include/linux/time.h extern unsigned long mktime(const unsign · line 78

Quoted 10 lines · Balbir Singh

/*
+ * sub = end - start, in normalized form
+ */

include/linux/time.h renamed from include/linux/time.h~delayacct-setup +6 -0
+static inline void timespec_sub(struct timespec *start, struct timespec *end,
+				struct timespec *sub)
+{
+	set_normalized_timespec(sub, end->tv_sec - start->tv_sec,
+				end->tv_nsec - start->tv_nsec);
+}

The interface might not be right here.

- I think "lhs" and "rhs" would be better names than "start" and "end". After all, we don't _know_ that the caller is using the two times as a start and an end. The caller might be taking the difference between two differences, for example.

- The existing timespec and timeval funtions tend to do return-by-value. So this would become

static inline struct timespec timespec_sub(struct timespec lhs,
struct timespec rhs)

(and given that it's inlined, the added overhead of passing the arguments by value will be zero)

- If we don't want to do that then at least let's get the arguments in a sane order:

static inline void timespec_sub(struct timespec *result,
struct timespec lhs, struct timespec rhs)

#2 lore raw
Quoted 19 lines · Andrew Morton

include/linux/time.h extern unsigned long mktime(const unsign · line 78

Quoted 10 lines · Balbir Singh

/*
+ * sub = end - start, in normalized form
+ */

include/linux/time.h renamed from include/linux/time.h~delayacct-setup +6 -0
+static inline void timespec_sub(struct timespec *start, struct timespec *end,
+				struct timespec *sub)
+{
+	set_normalized_timespec(sub, end->tv_sec - start->tv_sec,
+				end->tv_nsec - start->tv_nsec);
+}

The interface might not be right here.

- I think "lhs" and "rhs" would be better names than "start" and "end". After all, we don't _know_ that the caller is using the two times as a start and an end. The caller might be taking the difference between two differences, for example.

Quoted 8 lines

- The existing timespec and timeval funtions tend to do return-by-value. So this would become

static inline struct timespec timespec_sub(struct timespec lhs,
struct timespec rhs)

(and given that it's inlined, the added overhead of passing the arguments by value will be zero)

Agreed, I will make these changes.

Quoted 7 lines

- If we don't want to do that then at least let's get the arguments in a sane order:

static inline void timespec_sub(struct timespec *result,
struct timespec lhs, struct timespec rhs)

Signature · 3 lines
	Balbir Singh,
	Linux Technology Center,
	IBM Software Labs
#3 lore raw

PATCH 1/1 Fix the timespec_sub() interface (was Re: [Patch 1/8] Setup)

In reply to Andrew Morton
Quoted 25 lines · Andrew Morton

Review

Quoted 10 lines · Balbir Singh

/*
+ * sub = end - start, in normalized form
+ */

(quoted diff) +6 -0
+static inline void timespec_sub(struct timespec *start, struct timespec *end,
+				struct timespec *sub)
+{
+	set_normalized_timespec(sub, end->tv_sec - start->tv_sec,
+				end->tv_nsec - start->tv_nsec);
+}

The interface might not be right here.

- I think "lhs" and "rhs" would be better names than "start" and "end". After all, we don't _know_ that the caller is using the two times as a start and an end. The caller might be taking the difference between two differences, for example.

- The existing timespec and timeval funtions tend to do return-by-value. So this would become

static inline struct timespec timespec_sub(struct timespec lhs,
struct timespec rhs)

Quoted 9 lines

(and given that it's inlined, the added overhead of passing the arguments by value will be zero)

- If we don't want to do that then at least let's get the arguments in a sane order:

static inline void timespec_sub(struct timespec *result,
struct timespec lhs, struct timespec rhs)

Hi, Andrew,

Please find the updated patch, which changes the interface of timespec_sub() as suggested in the review comments

Changelog

1. Change the interface of timespec_sub() to return by value and rename the arguments. Use lhs,rhs instead of end,start

Changes under consideration

1. Migrate to the ktime interface (Thomas Gleixner)

Balbir Singh,
Linux Technology Center,
IBM Software Labs

---

 include/linux/time.h |   12 +++++++-----
 kernel/delayacct.c   |    2 +-
 2 files changed, 8 insertions(+), 6 deletions(-)
include/linux/time.h renamed from include/linux/time.h~timespec-sub-return-by-value +7 -5
diff -puN include/linux/time.h~timespec-sub-return-by-value include/linux/time.h
@@ -68,13 +68,15 @@ extern unsigned long mktime(const unsign
 extern void set_normalized_timespec(struct timespec *ts, time_t sec, long nsec);
 
 /*
- * sub = end - start, in normalized form
+ * sub = lhs - rhs, in normalized form
  */
-static inline void timespec_sub(struct timespec *start, struct timespec *end,
-				struct timespec *sub)
+static inline struct timespec timespec_sub(struct timespec *lhs,
+						struct timespec *rhs)
 {
-	set_normalized_timespec(sub, end->tv_sec - start->tv_sec,
-				end->tv_nsec - start->tv_nsec);
+	struct timespec ts_delta;
+	set_normalized_timespec(&ts_delta, lhs->tv_sec - rhs->tv_sec,
+				lhs->tv_nsec - rhs->tv_nsec);
+	return ts_delta;
 }
 
 /*
kernel/delayacct.c renamed from kernel/delayacct.c~timespec-sub-return-by-value +1 -1
diff -puN kernel/delayacct.c~timespec-sub-return-by-value kernel/delayacct.c
@@ -74,7 +74,7 @@ static inline void delayacct_end(struct 
 	s64 ns;
 
 	do_posix_clock_monotonic_gettime(end);
-	timespec_sub(&ts, start, end);
+	ts = timespec_sub(end, start);
 	ns = timespec_to_ns(&ts);
 	if (ns < 0)
 		return;

_

#4 lore raw

Re: [PATCH][delayacct] Fix the timespec_sub() interface (was Re: [Patch 1/8] Setup)

Quoted 10 lines · Balbir Singh

Please find the updated patch, which changes the interface of timespec_sub() as suggested in the review comments

...

/*
- * sub = end - start, in normalized form
+ * sub = lhs - rhs, in normalized form
*/

include/linux/time.h extern unsigned long mktime(const unsign · line 75

Quoted 5 lines
include/linux/time.h renamed from include/linux/time.h~timespec-sub-return-by-value +2 -2
-static inline void timespec_sub(struct timespec *start, struct timespec *end,
-				struct timespec *sub)
+static inline struct timespec timespec_sub(struct timespec *lhs,
+						struct timespec *rhs)
 {

I'd have thought that it would be more consistent and a saner interface to use pass-by-value:

static inline struct timespec timespec_sub(struct timespec lhs,
struct timespec rhs)

It should generate the same code.

I mentioned this last time - did you choose to not do this for some reason, or did it just slip past?

#5 lore raw

Re: [PATCH][delayacct] Fix the timespec_sub() interface (was Re: [Patch 1/8] Setup)

Quoted 20 lines · Andrew Morton
Quoted 10 lines · Balbir Singh

Please find the updated patch, which changes the interface of timespec_sub() as suggested in the review comments

...

/*
- * sub = end - start, in normalized form
+ * sub = lhs - rhs, in normalized form
*/

include/linux/time.h extern unsigned long mktime(const unsign · line 75

Quoted 5 lines
include/linux/time.h renamed from include/linux/time.h~timespec-sub-return-by-value +2 -2
-static inline void timespec_sub(struct timespec *start, struct timespec *end,
-				struct timespec *sub)
+static inline struct timespec timespec_sub(struct timespec *lhs,
+						struct timespec *rhs)
 {

I'd have thought that it would be more consistent and a saner interface to use pass-by-value:

Quoted 7 lines

static inline struct timespec timespec_sub(struct timespec lhs,
struct timespec rhs)

It should generate the same code.

I mentioned this last time - did you choose to not do this for some reason, or did it just slip past?

Sorry, that definitely slip past.

I'll send another update

Balbir Singh,
Linux Technology Center,
IBM Software Labs

#6 lore raw

Re: [PATCH][delayacct] Fix the timespec_sub() interface (was Re: [Patch 1/8] Setup)

Quoted 24 lines · Balbir Singh
Quoted 23 lines · Andrew Morton
Quoted 10 lines · Balbir Singh

Please find the updated patch, which changes the interface of timespec_sub() as suggested in the review comments

...

/*
- * sub = end - start, in normalized form
+ * sub = lhs - rhs, in normalized form
*/

Review

Quoted 5 lines
(quoted diff) +2 -2
-static inline void timespec_sub(struct timespec *start, struct timespec *end,
-				struct timespec *sub)
+static inline struct timespec timespec_sub(struct timespec *lhs,
+						struct timespec *rhs)
 {

I'd have thought that it would be more consistent and a saner interface to use pass-by-value:

static inline struct timespec timespec_sub(struct timespec lhs,
struct timespec rhs)

Quoted 9 lines
Quoted 4 lines

It should generate the same code.

I mentioned this last time - did you choose to not do this for some reason, or did it just slip past?

Sorry, that definitely slip past.

I'll send another update

Hi, Andrew,

Here is another attempt to do fix the interface.

Thanks for the review,
Balbir Singh,
Linux Technology Center,
IBM Software Labs

Changelog

1. Change the interface of timespec_sub() to return by value and rename the arguments. Use lhs,rhs instead of end,start.
2. Pass the arguments by value

---

 include/linux/time.h |   12 +++++++-----
 kernel/delayacct.c   |    2 +-
 2 files changed, 8 insertions(+), 6 deletions(-)
include/linux/time.h renamed from include/linux/time.h~timespec-sub-return-by-value +7 -5
diff -puN include/linux/time.h~timespec-sub-return-by-value include/linux/time.h
@@ -68,13 +68,15 @@ extern unsigned long mktime(const unsign
 extern void set_normalized_timespec(struct timespec *ts, time_t sec, long nsec);
 
 /*
- * sub = end - start, in normalized form
+ * sub = lhs - rhs, in normalized form
  */
-static inline void timespec_sub(struct timespec *start, struct timespec *end,
-				struct timespec *sub)
+static inline struct timespec timespec_sub(struct timespec lhs,
+						struct timespec rhs)
 {
-	set_normalized_timespec(sub, end->tv_sec - start->tv_sec,
-				end->tv_nsec - start->tv_nsec);
+	struct timespec ts_delta;
+	set_normalized_timespec(&ts_delta, lhs.tv_sec - rhs.tv_sec,
+				lhs.tv_nsec - rhs.tv_nsec);
+	return ts_delta;
 }
 
 /*
kernel/delayacct.c renamed from kernel/delayacct.c~timespec-sub-return-by-value +1 -1
diff -puN kernel/delayacct.c~timespec-sub-return-by-value kernel/delayacct.c
@@ -74,7 +74,7 @@ static inline void delayacct_end(struct 
 	s64 ns;
 
 	do_posix_clock_monotonic_gettime(end);
-	timespec_sub(&ts, start, end);
+	ts = timespec_sub(*end, *start);
 	ns = timespec_to_ns(&ts);
 	if (ns < 0)
 		return;

_

#7 lore raw
In reply to Balbir Singh
Quoted 8 lines · Balbir Singh
kernel/delayacct.c new file +7 -0
+static inline void delayacct_end(struct timespec *start, struct timespec *end,
+				u64 *total, u32 *count)
+{
+	struct timespec ts = {0, 0};
+	s64 ns;
+
+	do_posix_clock_monotonic_gettime(end);

kernel/delayacct.c line 86

Quoted 10 lines
kernel/delayacct.c new file +10 -0
+	timespec_sub(&ts, start, end);
+	ns = timespec_to_ns(&ts);
+	if (ns < 0)
+		return;
+
+	spin_lock(&current->delays->lock);
+	*total += ns;
+	(*count)++;
+	spin_unlock(&current->delays->lock);
+}

- too large to be inlined

- The initialisation of `ts' is unneeded (maybe it generated a bogus warning, but it won't do that if you switch timespec_sub to return-by-value)

#8 lore raw
Quoted 13 lines · Andrew Morton
Quoted 12 lines · Balbir Singh
kernel/delayacct.c new file +11 -0
+static inline void delayacct_end(struct timespec *start, struct timespec *end,
+				u64 *total, u32 *count)
+{
+	struct timespec ts = {0, 0};
+	s64 ns;
+
+	do_posix_clock_monotonic_gettime(end);
+	timespec_sub(&ts, start, end);
+	ns = timespec_to_ns(&ts);
+	if (ns < 0)
+		return;
Quoted 8 lines

kernel/delayacct.c line 86

Quoted 6 lines
kernel/delayacct.c new file +6 -0
+
+	spin_lock(&current->delays->lock);
+	*total += ns;
+	(*count)++;
+	spin_unlock(&current->delays->lock);
+}

- too large to be inlined

I will un-inline it.

Quoted 4 lines

- The initialisation of `ts' is unneeded (maybe it generated a bogus warning, but it won't do that if you switch timespec_sub to return-by-value)

gcc-4.1 does generate a bogus warning. I will switch to return by value and remove the initialization of `ts'

Thanks,
Balbir Singh,
Linux Technology Center,
IBM Software Labs

#9 lore raw

PATCH 1/1 un-inline delayacct_end(), remove initialization of ts (was Re: [Patch 1/8] Setup)

In reply to Andrew Morton
Quoted 22 lines · Andrew Morton
Quoted 8 lines · Balbir Singh
(quoted diff) +7 -0
+static inline void delayacct_end(struct timespec *start, struct timespec *end,
+				u64 *total, u32 *count)
+{
+	struct timespec ts = {0, 0};
+	s64 ns;
+
+	do_posix_clock_monotonic_gettime(end);

Review

Quoted 10 lines
(quoted diff) +10 -0
+	timespec_sub(&ts, start, end);
+	ns = timespec_to_ns(&ts);
+	if (ns < 0)
+		return;
+
+	spin_lock(&current->delays->lock);
+	*total += ns;
+	(*count)++;
+	spin_unlock(&current->delays->lock);
+}

- too large to be inlined

Quoted 3 lines

- The initialisation of `ts' is unneeded (maybe it generated a bogus warning, but it won't do that if you switch timespec_sub to return-by-value)

Hi, Andrew,

Here is an update to un-inline delayacct_end() and remove the initialization of ts to 0.

Balbir Singh,
Linux Technology Center,
IBM Software Labs

Changelog
1. Remove inlining of delayacct_end(), the function is too big to be inlined
2. Remove initialization of ts.

---

 kernel/delayacct.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
kernel/delayacct.c renamed from kernel/delayacct.c~remove-initialization-of-ts-and-inline +2 -2
diff -puN kernel/delayacct.c~remove-initialization-of-ts-and-inline kernel/delayacct.c
@@ -67,10 +67,10 @@ static inline void delayacct_start(struc
  * its timestamps (@start, @end), accumalator (@total) and @count
  */
 
-static inline void delayacct_end(struct timespec *start, struct timespec *end,
+static void delayacct_end(struct timespec *start, struct timespec *end,
 				u64 *total, u32 *count)
 {
-	struct timespec ts = {0, 0};
+	struct timespec ts;
 	s64 ns;
 
 	do_posix_clock_monotonic_gettime(end);

_

#10 lore raw
In reply to Balbir Singh

include/linux/time.h extern unsigned long mktime(const unsign · line 78

Quoted 9 lines · Balbir Singh

/*
+ * sub = end - start, in normalized form
+ */

include/linux/time.h renamed from include/linux/time.h~delayacct-setup +6 -0
+static inline void timespec_sub(struct timespec *start, struct timespec *end,
+				struct timespec *sub)
+{
+	set_normalized_timespec(sub, end->tv_sec - start->tv_sec,
+				end->tv_nsec - start->tv_nsec);
+}

Please use the existing ktime_t functions for that purpose. The ktime_t format has nanosecond resolution and is optimized for 32/64bit machines.

kernel/delayacct.c line 63

Quoted 4 lines
kernel/delayacct.c new file +4 -0
+static inline void delayacct_start(struct timespec *start)
+{
+	do_posix_clock_monotonic_gettime(start);
+}

Please get rid of this wrapper and use the ktime based functions for that.

kernel/delayacct.c line 71

Quoted 7 lines
kernel/delayacct.c new file +7 -0
+/*
+ * Finish delay accounting for a statistic using
+ * its timestamps (@start, @end), accumalator (@total) and @count
+ */
+
+static inline void delayacct_end(struct timespec *start, struct timespec *end,
+				u64 *total, u32 *count)

Please use ktime_t for total.

kernel/delayacct.c line 80

Quoted 9 lines
kernel/delayacct.c new file +9 -0
+{
+	struct timespec ts = {0, 0};
+	s64 ns;
+
+	do_posix_clock_monotonic_gettime(end);
+	timespec_sub(&ts, start, end);
+	ns = timespec_to_ns(&ts);
+	if (ns < 0)
+		return;

monotonic time is monotonic increasing. So delta is always >= 0 !

tglx

#11 lore raw
Quoted 44 lines · Thomas Gleixner

include/linux/time.h extern unsigned long mktime(const unsign · line 78

Quoted 9 lines · Balbir Singh

/*
+ * sub = end - start, in normalized form
+ */

include/linux/time.h renamed from include/linux/time.h~delayacct-setup +6 -0
+static inline void timespec_sub(struct timespec *start, struct timespec *end,
+				struct timespec *sub)
+{
+	set_normalized_timespec(sub, end->tv_sec - start->tv_sec,
+				end->tv_nsec - start->tv_nsec);
+}

Please use the existing ktime_t functions for that purpose. The ktime_t format has nanosecond resolution and is optimized for 32/64bit machines.

kernel/delayacct.c line 63

Quoted 4 lines
kernel/delayacct.c new file +4 -0
+static inline void delayacct_start(struct timespec *start)
+{
+	do_posix_clock_monotonic_gettime(start);
+}

Please get rid of this wrapper and use the ktime based functions for that.

kernel/delayacct.c line 71

Quoted 7 lines
kernel/delayacct.c new file +7 -0
+/*
+ * Finish delay accounting for a statistic using
+ * its timestamps (@start, @end), accumalator (@total) and @count
+ */
+
+static inline void delayacct_end(struct timespec *start, struct timespec *end,
+				u64 *total, u32 *count)

Please use ktime_t for total.

kernel/delayacct.c line 80

Quoted 9 lines
kernel/delayacct.c new file +9 -0
+{
+	struct timespec ts = {0, 0};
+	s64 ns;
+
+	do_posix_clock_monotonic_gettime(end);
+	timespec_sub(&ts, start, end);
+	ns = timespec_to_ns(&ts);
+	if (ns < 0)
+		return;

monotonic time is monotonic increasing. So delta is always >= 0 !

Quoted 5 lines

tglx

I am going through the ktime interface and it seems interesting. I will look into it and see if we can migrate the interface to use ktime

Balbir Singh,
Linux Technology Center,
IBM Software Labs