mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg KH <gregkh@suse.de>
To: linux-kernel@vger.kernel.org, stable@kernel.org
Cc: stable-review@kernel.org, torvalds@linux-foundation.org,
	akpm@linux-foundation.org, alan@lxorguk.ukuu.org.uk,
	Venkatesh Pallipadi <venki@google.com>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Ingo Molnar <mingo@elte.hu>, Mike Galbraith <efault@gmx.de>
Subject: [104/115] sched: Do not account irq time to current task
Date: Tue, 15 Feb 2011 17:46:10 -0800	[thread overview]
Message-ID: <20110216014704.651579175@clark.kroah.org> (raw)
In-Reply-To: <20110216014741.GA24678@kroah.com>

2.6.32-longterm review patch.  If anyone has any objections, please let us know.

------------------

Commit: 305e6835e05513406fa12820e40e4a8ecb63743c upstream

Scheduler accounts both softirq and interrupt processing times to the
currently running task. This means, if the interrupt processing was
for some other task in the system, then the current task ends up being
penalized as it gets shorter runtime than otherwise.

Change sched task accounting to acoount only actual task time from
currently running task. Now update_curr(), modifies the delta_exec to
depend on rq->clock_task.

Note that this change only handles CONFIG_IRQ_TIME_ACCOUNTING case. We can
extend this to CONFIG_VIRT_CPU_ACCOUNTING with minimal effort. But, thats
for later.

This change will impact scheduling behavior in interrupt heavy conditions.

Tested on a 4-way system with eth0 handled by CPU 2 and a network heavy
task (nc) running on CPU 3 (and no RSS/RFS). With that I have CPU 2
spending 75%+ of its time in irq processing. CPU 3 spending around 35%
time running nc task.

Now, if I run another CPU intensive task on CPU 2, without this change
/proc/<pid>/schedstat shows 100% of time accounted to this task. With this
change, it rightly shows less than 25% accounted to this task as remaining
time is actually spent on irq processing.

Signed-off-by: Venkatesh Pallipadi <venki@google.com>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <1286237003-12406-7-git-send-email-venki@google.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Mike Galbraith <efault@gmx.de>
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 kernel/sched.c      |   40 ++++++++++++++++++++++++++++++++++++++--
 kernel/sched_fair.c |    4 ++--
 kernel/sched_rt.c   |    8 ++++----
 3 files changed, 44 insertions(+), 8 deletions(-)

--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -525,6 +525,7 @@ struct rq {
 	struct mm_struct *prev_mm;
 
 	u64 clock;
+	u64 clock_task;
 
 	atomic_t nr_iowait;
 
@@ -620,9 +621,17 @@ static inline int cpu_of(struct rq *rq)
 #define cpu_curr(cpu)		(cpu_rq(cpu)->curr)
 #define raw_rq()		(&__raw_get_cpu_var(runqueues))
 
+static u64 irq_time_cpu(int cpu);
+
 inline void update_rq_clock(struct rq *rq)
 {
+	int cpu = cpu_of(rq);
+	u64 irq_time;
+
 	rq->clock = sched_clock_cpu(cpu_of(rq));
+	irq_time = irq_time_cpu(cpu);
+	if (rq->clock - irq_time > rq->clock_task)
+		rq->clock_task = rq->clock - irq_time;
 }
 
 /*
@@ -1809,6 +1818,18 @@ static inline void __set_task_cpu(struct
 
 #ifdef CONFIG_IRQ_TIME_ACCOUNTING
 
+/*
+ * There are no locks covering percpu hardirq/softirq time.
+ * They are only modified in account_system_vtime, on corresponding CPU
+ * with interrupts disabled. So, writes are safe.
+ * They are read and saved off onto struct rq in update_rq_clock().
+ * This may result in other CPU reading this CPU's irq time and can
+ * race with irq/account_system_vtime on this CPU. We would either get old
+ * or new value (or semi updated value on 32 bit) with a side effect of
+ * accounting a slice of irq time to wrong task when irq is in progress
+ * while we read rq->clock. That is a worthy compromise in place of having
+ * locks on each irq in account_system_time.
+ */
 static DEFINE_PER_CPU(u64, cpu_hardirq_time);
 static DEFINE_PER_CPU(u64, cpu_softirq_time);
 
@@ -1825,6 +1846,14 @@ void disable_sched_clock_irqtime(void)
 	sched_clock_irqtime = 0;
 }
 
+static u64 irq_time_cpu(int cpu)
+{
+	if (!sched_clock_irqtime)
+		return 0;
+
+	return per_cpu(cpu_softirq_time, cpu) + per_cpu(cpu_hardirq_time, cpu);
+}
+
 void account_system_vtime(struct task_struct *curr)
 {
 	unsigned long flags;
@@ -1854,6 +1883,13 @@ void account_system_vtime(struct task_st
 	local_irq_restore(flags);
 }
 
+#else
+
+static u64 irq_time_cpu(int cpu)
+{
+	return 0;
+}
+
 #endif
 
 #include "sched_stats.h"
@@ -3295,7 +3331,7 @@ int can_migrate_task(struct task_struct
 	 * 2) too many balance attempts have failed.
 	 */
 
-	tsk_cache_hot = task_hot(p, rq->clock, sd);
+	tsk_cache_hot = task_hot(p, rq->clock_task, sd);
 	if (!tsk_cache_hot ||
 		sd->nr_balance_failed > sd->cache_nice_tries) {
 #ifdef CONFIG_SCHEDSTATS
@@ -5083,7 +5119,7 @@ static u64 do_task_delta_exec(struct tas
 
 	if (task_current(rq, p)) {
 		update_rq_clock(rq);
-		ns = rq->clock - p->se.exec_start;
+		ns = rq->clock_task - p->se.exec_start;
 		if ((s64)ns < 0)
 			ns = 0;
 	}
--- a/kernel/sched_fair.c
+++ b/kernel/sched_fair.c
@@ -496,7 +496,7 @@ __update_curr(struct cfs_rq *cfs_rq, str
 static void update_curr(struct cfs_rq *cfs_rq)
 {
 	struct sched_entity *curr = cfs_rq->curr;
-	u64 now = rq_of(cfs_rq)->clock;
+	u64 now = rq_of(cfs_rq)->clock_task;
 	unsigned long delta_exec;
 
 	if (unlikely(!curr))
@@ -579,7 +579,7 @@ update_stats_curr_start(struct cfs_rq *c
 	/*
 	 * We are starting a new run period:
 	 */
-	se->exec_start = rq_of(cfs_rq)->clock;
+	se->exec_start = rq_of(cfs_rq)->clock_task;
 }
 
 /**************************************************
--- a/kernel/sched_rt.c
+++ b/kernel/sched_rt.c
@@ -603,7 +603,7 @@ static void update_curr_rt(struct rq *rq
 	if (!task_has_rt_policy(curr))
 		return;
 
-	delta_exec = rq->clock - curr->se.exec_start;
+	delta_exec = rq->clock_task - curr->se.exec_start;
 	if (unlikely((s64)delta_exec < 0))
 		delta_exec = 0;
 
@@ -612,7 +612,7 @@ static void update_curr_rt(struct rq *rq
 	curr->se.sum_exec_runtime += delta_exec;
 	account_group_exec_runtime(curr, delta_exec);
 
-	curr->se.exec_start = rq->clock;
+	curr->se.exec_start = rq->clock_task;
 	cpuacct_charge(curr, delta_exec);
 
 	sched_rt_avg_update(rq, delta_exec);
@@ -1069,7 +1069,7 @@ static struct task_struct *_pick_next_ta
 	} while (rt_rq);
 
 	p = rt_task_of(rt_se);
-	p->se.exec_start = rq->clock;
+	p->se.exec_start = rq->clock_task;
 
 	return p;
 }
@@ -1735,7 +1735,7 @@ static void set_curr_task_rt(struct rq *
 {
 	struct task_struct *p = rq->curr;
 
-	p->se.exec_start = rq->clock;
+	p->se.exec_start = rq->clock_task;
 
 	/* The running task is never eligible for pushing */
 	dequeue_pushable_task(rq, p);



  parent reply	other threads:[~2011-02-16  1:54 UTC|newest]

Thread overview: 137+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-16  1:47 [000/115] 2.6.32.29-longterm review Greg KH
2011-02-16  1:44 ` [001/115] staging: usbip: remove double giveback of URB Greg KH
2011-02-16  1:44 ` [002/115] USB: EHCI: ASPM quirk of ISOC on AMD SB800 Greg KH
2011-02-16  1:44 ` [003/115] rt2x00: add device id for windy31 usb device Greg KH
2011-02-16  1:44 ` [004/115] ALSA: snd-usb-us122l: Fix missing NULL checks Greg KH
2011-02-16  1:44 ` [005/115] hwmon: (via686a) Initialize fan_div values Greg KH
2011-02-16  1:44 ` [006/115] USB: serial: handle Data Carrier Detect changes Greg KH
2011-02-16  1:44 ` [007/115] USB: CP210x Add two device IDs Greg KH
2011-02-16  1:44 ` [008/115] USB: CP210x Removed incorrect device ID Greg KH
2011-02-16  1:44 ` [009/115] USB: usb-storage: unusual_devs update for Cypress ATACB Greg KH
2011-02-16  1:44 ` [010/115] USB: usb-storage: unusual_devs update for TrekStor DataStation maxi g.u external hard drive enclosure Greg KH
2011-02-16  1:44 ` [011/115] USB: usb-storage: unusual_devs entry for CamSport Evo Greg KH
2011-02-16  1:44 ` [012/115] USB: usb-storage: unusual_devs entry for Coby MP3 player Greg KH
2011-02-16  1:44 ` [013/115] USB: serial: Updated support for ICOM devices Greg KH
2011-02-16  1:44 ` [014/115] USB: adding USB support for Cinterions HC2x, EU3 and PH8 products Greg KH
2011-02-16  1:44 ` [015/115] USB: EHCI: ASPM quirk of ISOC on AMD Hudson Greg KH
2011-02-16  1:44 ` [016/115] USB: EHCI: fix DMA deallocation bug Greg KH
2011-02-16  1:44 ` [017/115] USB: g_printer: fix bug in module parameter definitions Greg KH
2011-02-16  1:44 ` [018/115] USB: io_edgeport: fix the reported firmware major and minor Greg KH
2011-02-16  1:44 ` [019/115] USB: ti_usb: fix module removal Greg KH
2011-02-16  1:44 ` [020/115] USB: Storage: Add unusual_devs entry for VTech Kidizoom Greg KH
2011-02-16  1:44 ` [021/115] USB: ftdi_sio: add ST Micro Connect Lite uart support Greg KH
2011-02-16  1:44 ` [022/115] USB: cdc-acm: Adding second ACM channel support for Nokia N8 Greg KH
2011-02-16  1:44 ` [023/115] USB: ftdi_sio: Add VID=0x0647, PID=0x0100 for Acton Research spectrograph Greg KH
2011-02-16  1:44 ` [024/115] USB: prevent buggy hubs from crashing the USB stack Greg KH
2011-02-23  8:06   ` Alexander Holler
2011-02-23  8:40     ` Alexander Holler
2011-02-23 15:26       ` Alan Stern
2011-02-24  8:57         ` Felipe Balbi
2011-02-24  9:15           ` Alexander Holler
2011-02-24  9:16             ` Felipe Balbi
2011-02-24 17:18               ` Greg KH
2011-02-24 17:23                 ` Felipe Balbi
2011-02-24 17:57                   ` Alan Stern
2011-02-24 18:11                     ` Alexander Holler
2011-02-24 18:24                       ` Greg KH
2011-02-24 18:12                     ` Greg KH
2011-02-24 18:16                       ` Greg KH
2011-02-24  9:53           ` Michael Jones
2011-02-16  1:44 ` [025/115] staging: comedi: add support for newer jr3 1-channel pci board Greg KH
2011-02-16  1:44 ` [026/115] staging: comedi: ni_labpc: Use shared IRQ for PCMCIA card Greg KH
2011-02-16  1:44 ` [027/115] Staging: hv: fix sysfs symlink on hv block device Greg KH
2011-02-16  1:44 ` [028/115] staging: hv: Enable sending GARP packet after live migration Greg KH
2011-02-16  1:44 ` [029/115] [S390] hvc_iucv: allocate memory buffers for IUCV in zone DMA Greg KH
2011-02-16  1:44 ` [030/115] iwlagn: enable only rfkill interrupt when device is down Greg KH
2011-02-16  1:44 ` [031/115] ath9k: Fix bug in delimiter padding computation Greg KH
2011-02-16  1:44 ` [032/115] [S390] correct vdso version string Greg KH
2011-02-16  1:44 ` [033/115] [SCSI] fix medium error problems with some arrays which can cause data corruption Greg KH
2011-02-16  1:45 ` [034/115] [SCSI] libsas: fix runaway error handler problem Greg KH
2011-02-16  1:45 ` [035/115] [SCSI] mpt2sas: Fix device removal handshake for zoned devices Greg KH
2011-02-16  1:45 ` [036/115] [SCSI] mpt2sas: Correct resizing calculation for max_queue_depth Greg KH
2011-02-16  1:45 ` [037/115] [SCSI] mpt2sas: Kernel Panic during Large Topology discovery Greg KH
2011-02-16  1:45 ` [038/115] [media] radio-aimslab.c: Fix gcc 4.5+ bug Greg KH
2011-02-16  1:45 ` [039/115] [media] em28xx: Fix audio input for Terratec Grabby Greg KH
2011-02-16  1:45 ` [040/115] ALSA : au88x0 - Limit number of channels to fix Oops via OSS emu Greg KH
2011-02-16  1:45 ` [041/115] ALSA: HDA: Fix dmesg output of HDMI supported bits Greg KH
2011-02-16  1:45 ` [042/115] ALSA: hda - Fix memory leaks in conexant jack arrays Greg KH
2011-02-16  1:45 ` [043/115] Input: i8042 - introduce notimeout blacklist for Dell Vostro V13 Greg KH
2011-02-16  1:45 ` [044/115] input: bcm5974: Add support for MacBookAir3 Greg KH
2011-02-16  1:45 ` [045/115] ALSA: hrtimer: handle delayed timer interrupts Greg KH
2011-02-16  1:45 ` [046/115] ASoC: WM8990: msleep() takes milliseconds not jiffies Greg KH
2011-02-16  1:45 ` [047/115] ASoC: Blackfin AC97: fix build error after multi-component update Greg KH
2011-02-16  1:45 ` [048/115] NFS: Fix "kernel BUG at fs/aio.c:554!" Greg KH
2011-02-16  1:45 ` [049/115] rtc-cmos: fix suspend/resume Greg KH
2011-02-16  1:45 ` [050/115] iwlagn: Re-enable RF_KILL interrupt when down Greg KH
2011-02-16  1:45 ` [051/115] rapidio: fix hang on RapidIO doorbell queue full condition Greg KH
2011-02-16  1:45 ` [052/115] PCI: pci-stub: ignore zero-length id parameters Greg KH
2011-02-16  1:45 ` [053/115] virtio: remove virtio-pci root device Greg KH
2011-02-16  1:45 ` [054/115] ds2760_battery: Fix calculation of time_to_empty_now Greg KH
2011-02-16  1:45 ` [055/115] p54: fix sequence no. accounting off-by-one error Greg KH
2011-02-16  1:45 ` [056/115] i2c: Unregister dummy devices last on adapter removal Greg KH
2011-02-16  1:45 ` [057/115] serial: unbreak billionton CF card Greg KH
2011-02-16  1:45 ` [058/115] ptrace: use safer wake up on ptrace_detach() Greg KH
2011-02-16  1:45 ` [059/115] x86, mtrr: Avoid MTRR reprogramming on BP during boot on UP platforms Greg KH
2011-02-16  1:45 ` [060/115] fix jiffy calculations in calibrate_delay_direct to handle overflow Greg KH
2011-02-16  1:45 ` [061/115] USB: serial: pl2303: Hybrid reader Uniform HCR331 Greg KH
2011-02-16  1:45 ` [062/115] drivers: update to pl2303 usb-serial to support Motorola cables Greg KH
2011-02-16  1:45 ` [063/115] klist: Fix object alignment on 64-bit Greg KH
2011-02-16  1:45 ` [064/115] powerpc: Fix some 6xx/7xxx CPU setup functions Greg KH
2011-02-16  1:45 ` [065/115] parisc : Remove broken line wrapping handling pdc_iodc_print() Greg KH
2011-02-16  1:45 ` [066/115] kernel/smp.c: fix smp_call_function_many() SMP race Greg KH
2011-02-16  1:45 ` [067/115] hostap_cs: fix sleeping function called from invalid context Greg KH
2011-02-16  1:45 ` [068/115] md: fix regression with re-adding devices to arrays with no metadata Greg KH
2011-02-16  1:45 ` [069/115] pata_mpc52xx: inherit from ata_bmdma_port_ops Greg KH
2011-02-16  1:45 ` [070/115] TPM: Long default timeout fix Greg KH
2011-02-16  1:45 ` [071/115] tpm_tis: Use timeouts returned from TPM Greg KH
2011-02-16  1:45 ` [072/115] SELinux: define permissions for DCB netlink messages Greg KH
2011-02-16  1:45 ` [073/115] SELinux: do not compute transition labels on mountpoint labeled filesystems Greg KH
2011-02-16  1:45 ` [074/115] ieee80211: correct IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK macro Greg KH
2011-02-16  1:45 ` [075/115] dm: dont take i_mutex to change device size Greg KH
2011-02-16  1:45 ` [076/115] dm mpath: disable blk_abort_queue Greg KH
2011-02-16  1:45 ` [077/115] drm/radeon/kms: add quirk for Mac Radeon HD 2600 card Greg KH
2011-02-16  1:45 ` [078/115] drm/radeon/kms: make the mac rv630 quirk generic Greg KH
2011-02-16  1:45 ` [079/115] drm/radeon/kms: add pll debugging output Greg KH
2011-02-16  1:45 ` [080/115] drm/radeon: remove 0x4243 pci id Greg KH
2011-02-16  1:45 ` [081/115] drm/radeon/kms: fix s/r issues with bios scratch regs Greg KH
2011-02-16  1:45 ` [082/115] drm/i915/lvds: Add AOpen i915GMm-HFS to the list of false-positive LVDS Greg KH
2011-02-16  1:45 ` [083/115] drm/i915: Add dependency on CONFIG_TMPFS Greg KH
2011-02-16  1:45 ` [084/115] x86, mm: avoid possible bogus tlb entries by clearing prev mm_cpumask after switching mm Greg KH
2011-02-16  1:45 ` [085/115] usb: Realloc xHCI structures after a hub is verified Greg KH
2011-02-16  1:45 ` [086/115] sched: Remove USER_SCHED Greg KH
2011-02-16  1:45 ` [087/115] sched: Remove remaining USER_SCHED code Greg KH
2011-02-16  1:45 ` [088/115] sched: Move sched_avg_update() to update_cpu_load() Greg KH
2011-02-16  1:45 ` [089/115] sched: Increment cache_nice_tries only on periodic lb Greg KH
2011-02-16  1:45 ` [090/115] sched: Try not to migrate higher priority RT tasks Greg KH
2011-02-16  1:45 ` [091/115] sched: Give CPU bound RT tasks preference Greg KH
2011-02-16  1:45 ` [092/115] sched: suppress RCU lockdep splat in task_fork_fair Greg KH
2011-02-16  1:45 ` [093/115] sched: fix RCU lockdep splat from task_group() Greg KH
2011-02-16  1:46 ` [094/115] sched: Do not consider SCHED_IDLE tasks to be cache hot Greg KH
2011-02-16  1:46 ` [095/115] sched: Set group_imb only a task can be pulled from the busiest cpu Greg KH
2011-02-16  1:46 ` [096/115] sched: Force balancing on newidle balance if local group has capacity Greg KH
2011-02-16  1:46 ` [097/115] sched: Drop group_capacity to 1 only if local group has extra capacity Greg KH
2011-02-16  1:46 ` [098/115] sched: Fix softirq time accounting Greg KH
2011-02-16  1:46 ` [099/115] sched: Consolidate account_system_vtime extern declaration Greg KH
2011-02-16  1:46 ` [100/115] sched: Remove unused PF_ALIGNWARN flag Greg KH
2011-02-16  1:46 ` [101/115] sched: Add a PF flag for ksoftirqd identification Greg KH
2011-02-16  1:46 ` [102/115] sched: Add IRQ_TIME_ACCOUNTING, finer accounting of irq time Greg KH
2011-02-16  1:46 ` [103/115] x86: Add IRQ_TIME_ACCOUNTING Greg KH
2011-02-16  1:46 ` Greg KH [this message]
2011-02-16  1:46 ` [105/115] sched: Remove irq time from available CPU power Greg KH
2011-02-16  1:46 ` [106/115] sched: Call tick_check_idle before __irq_enter Greg KH
2011-02-16  1:46 ` [107/115] sched: Export account_system_vtime() Greg KH
2011-02-16  1:46 ` [108/115] sched, cgroup: Fixup broken cgroup movement Greg KH
2011-02-16  1:46 ` [109/115] sched: Use group weight, idle cpu metrics to fix imbalances during idle Greg KH
2011-02-16  1:46 ` [110/115] sched: Fix cross-sched-class wakeup preemption Greg KH
2011-02-16  1:46 ` [111/115] sched: Fix volanomark performance regression Greg KH
2011-02-16  1:46 ` [112/115] sched: Fix idle balancing Greg KH
2011-02-16  1:46 ` [113/115] sched: Fix wake_affine() vs RT tasks Greg KH
2011-02-16  1:46 ` [114/115] sched: Remove some dead code Greg KH
2011-02-16  7:37   ` Dan Carpenter
2011-02-16  7:56     ` Mike Galbraith
2011-02-16  8:30       ` Ingo Molnar
2011-02-16  9:24         ` [Stable-review] " Willy Tarreau
2011-02-16  1:46 ` [115/115] kernel/user.c: add lock release annotation on free_user() Greg KH
2011-02-16 13:51 ` [000/115] 2.6.32.29-longterm review Ian Campbell
2011-02-17  0:35   ` Greg KH
2011-02-17  9:22     ` Ian Campbell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110216014704.651579175@clark.kroah.org \
    --to=gregkh@suse.de \
    --cc=a.p.zijlstra@chello.nl \
    --cc=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=efault@gmx.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=stable-review@kernel.org \
    --cc=stable@kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=venki@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®