linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: klamm@yandex-team.ru
To: peterz@infradead.org, mingo@redhat.com, linux-kernel@vger.kernel.org
Cc: stfomichev@yandex-team.ru, Roman Gushchin <klamm@yandex-team.ru>
Subject: [PATCH 04/19] smart: helper functions for smart_data manipulations
Date: Thu,  4 Sep 2014 20:30:50 +0400	[thread overview]
Message-ID: <1409848265-17150-4-git-send-email-klamm@yandex-team.ru> (raw)
In-Reply-To: <1409848265-17150-1-git-send-email-klamm@yandex-team.ru>

From: Roman Gushchin <klamm@yandex-team.ru>

This commit adds the following helper functions:
acquire_core() - acquires per-core lock
release_core() - releases per-core lock
core_acquired() - checks if per-core lock is acquired
core_is_rt_free() - checks if there are no rt tasks on specified core
core_rt_free_thread() - finds free SMT thread on specified core
find_rt_free_core() - finds free core starting with specified core

Signed-off-by: Roman Gushchin <klamm@yandex-team.ru>
---
 kernel/sched/sched.h | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 87 insertions(+)

diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 7e26454..4603096 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -1418,6 +1418,89 @@ static inline int next_core(int cpu)
 	return smart_data(cpu).core_next;
 }
 
+static inline int acquire_core(int cpu)
+{
+	return (0 == atomic_cmpxchg(&smart_data(cpu).core_locked, 0, 1));
+}
+
+static inline void release_core(int cpu)
+{
+	atomic_set(&smart_data(cpu).core_locked, 0);
+}
+
+static inline int core_acquired(int cpu)
+{
+	return atomic_read(&smart_data(cpu).core_locked);
+}
+
+static inline int core_is_rt_free(int core)
+{
+	struct rq *rq;
+	int cpu;
+	unsigned int nr_rt;
+	struct task_struct *task;
+
+	for_each_cpu(cpu, topology_thread_cpumask(core)) {
+		rq = cpu_rq(cpu);
+
+		if (rq->rt.rt_throttled)
+			return 0;
+
+		nr_rt = rq->rt.rt_nr_running;
+		if (nr_rt) {
+			if (nr_rt > 1)
+				return 0;
+
+			task = ACCESS_ONCE(rq->curr);
+			if (task->mm)
+				return 0;
+		}
+	}
+
+	return 1;
+}
+
+static inline int core_rt_free_thread(int core)
+{
+	struct rq *rq;
+	int cpu;
+
+	for_each_cpu(cpu, topology_thread_cpumask(core)) {
+		rq = cpu_rq(cpu);
+
+		if (rq->rt.rt_throttled)
+			continue;
+
+		if (!rq->rt.rt_nr_running)
+			return cpu;
+	}
+
+	return -1;
+}
+
+static inline int find_rt_free_core(int start_cpu, struct task_struct *task)
+{
+	int core;
+
+	/* Local cores */
+	core = cpu_core_id(start_cpu);
+	do {
+		if (!core_acquired(core) && core_is_rt_free(core) &&
+		    cpumask_test_cpu(core, tsk_cpus_allowed(task)))
+			return core;
+	} while (core = next_core(core), core != cpu_core_id(start_cpu));
+
+	/* Remote cores */
+	core = core_node_sibling(start_cpu);
+	do {
+		if (!core_acquired(core) && core_is_rt_free(core) &&
+		    cpumask_test_cpu(core, tsk_cpus_allowed(task)))
+			return core;
+	} while (core = next_core(core), core != core_node_sibling(start_cpu));
+
+	return -1;
+}
+
 void build_smart_topology(void);
 
 #else /* CONFIG_SMART */
@@ -1430,4 +1513,8 @@ static inline bool smart_enabled(void)
 	return false;
 }
 
+static inline void release_core(int cpu)
+{
+}
+
 #endif /* CONFIG_SMART */
-- 
1.9.3


  parent reply	other threads:[~2014-09-04 16:31 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-04 12:20 [RFC] smt-aware rt load balancer Roman Gushchin
2014-09-04 15:40 ` Peter Zijlstra
2014-09-04 16:30 ` [PATCH 01/19] smart: define and build per-core data structures klamm
2014-09-04 16:30   ` [PATCH 02/19] smart: add config option for SMART-related code klamm
2014-09-04 16:30   ` [PATCH 03/19] smart: introduce smart_enabled() klamm
2014-09-04 16:30   ` klamm [this message]
2014-09-04 16:30   ` [PATCH 05/19] smart: CPU selection logic klamm
2014-09-04 16:30   ` [PATCH 06/19] smart: use CPU selection logic if smart is enabled klamm
2014-09-21 17:31     ` Pavel Machek
2014-09-04 16:30   ` [PATCH 07/19] smart: balance load between nodes klamm
2014-09-04 16:30   ` [PATCH 08/19] smart: smart pull klamm
2014-09-04 16:30   ` [PATCH 09/19] smart: throttle CFS tasks by affinning to first SMT thread klamm
2014-09-04 16:30   ` [PATCH 10/19] smart: smart gathering klamm
2014-09-04 16:30   ` [PATCH 11/19] smart: smart debug klamm
2014-09-04 16:30   ` [PATCH 12/19] smart: cgroup interface for smart klamm
2014-09-04 16:30   ` [PATCH 13/19] smart: nosmart boot option klamm
2014-09-04 16:31   ` [PATCH 14/19] smart: smart-related sysctl's klamm
2014-09-04 16:31   ` [PATCH 15/19] smart: decrease default rt_period/rt_runtime values klamm
2014-09-04 16:31   ` [PATCH 16/19] smart: change default RR timeslice to 5ms klamm
2014-09-04 16:31   ` [PATCH 17/19] smart: disable RT runtime sharing klamm
2014-09-04 16:31   ` [PATCH 18/19] hrtimers: calculate expires_next after all timers are executed klamm
2014-09-04 16:31   ` [PATCH 19/19] smart: add description to the README file klamm
2014-09-04 16:49 ` [RFC] smt-aware rt load balancer Peter Zijlstra
2014-09-04 17:06   ` Roman Gushchin

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=1409848265-17150-4-git-send-email-klamm@yandex-team.ru \
    --to=klamm@yandex-team.ru \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=stfomichev@yandex-team.ru \
    /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;
as well as URLs for NNTP newsgroup(s).