Skip to content
Snippets Groups Projects
Commit 9e7ee944 authored by Nadav Har'El's avatar Nadav Har'El
Browse files

Allow creation of a new sched::thread pinned to a specific CPU.

Previously, we had the option to create a pinned thread, but it always
runs on the same CPU as the current thread, which is kind of odd. Changed
the boolean attribute "pinned" to a cpu* attribute specifying the cpu to
pin to.

Example code to run a start a new thread pinned on cpu 1:
new sched::thread([&]{...}, sched::thread::attr(sched::cpus[1]));

I need this feature to test the cross-CPU TLB flushing feature - I need
to be able to run two threads on two different CPUs.
parent 74ed795b
No related branches found
No related tags found
No related merge requests found
...@@ -100,15 +100,14 @@ void smp_launch() ...@@ -100,15 +100,14 @@ void smp_launch()
if (c == boot_cpu) { if (c == boot_cpu) {
sched::thread::current()->_cpu = c; sched::thread::current()->_cpu = c;
c->init_on_cpu(); c->init_on_cpu();
sched::thread::attr attr; (new sched::thread([c] { c->load_balance(); },
attr.pinned = true; sched::thread::attr(c)))->start();
(new sched::thread([c] { c->load_balance(); }, attr))->start();
c->idle_thread.start(); c->idle_thread.start();
continue; continue;
} }
sched::thread::attr attr; sched::thread::attr attr;
attr.stack = { new char[81920], 81920 }; attr.stack = { new char[81920], 81920 };
attr.pinned = true; attr.pinned_cpu = c;
c->bringup_thread = new sched::thread([=] { ap_bringup(c); }, attr, true); c->bringup_thread = new sched::thread([=] { ap_bringup(c); }, attr, true);
} }
apic->write(apicreg::ICR, 0xc4500); // INIT apic->write(apicreg::ICR, 0xc4500); // INIT
......
...@@ -38,14 +38,9 @@ constexpr u64 max_slice = 10_ms; ...@@ -38,14 +38,9 @@ constexpr u64 max_slice = 10_ms;
namespace sched { namespace sched {
void schedule_force();
const thread::attr idle_thread_attr(true);
cpu::cpu() cpu::cpu()
: idle_thread([this] { idle(); }, idle_thread_attr) : idle_thread([this] { idle(); }, thread::attr(this))
{ {
idle_thread._cpu = this;
} }
void cpu::schedule(bool yield) void cpu::schedule(bool yield)
...@@ -191,7 +186,7 @@ void cpu::load_balance() ...@@ -191,7 +186,7 @@ void cpu::load_balance()
} }
with_lock(irq_lock, [this, min] { with_lock(irq_lock, [this, min] {
auto i = std::find_if(runqueue.rbegin(), runqueue.rend(), auto i = std::find_if(runqueue.rbegin(), runqueue.rend(),
[](thread& t) { return !t._attr.pinned; }); [](thread& t) { return !t._attr.pinned_cpu; });
if (i == runqueue.rend()) { if (i == runqueue.rend()) {
return; return;
} }
...@@ -293,7 +288,7 @@ thread::~thread() ...@@ -293,7 +288,7 @@ thread::~thread()
void thread::start() void thread::start()
{ {
_cpu = current()->tcpu(); _cpu = _attr.pinned_cpu ? _attr.pinned_cpu : current()->tcpu();
assert(_status == status::unstarted); assert(_status == status::unstarted);
_status.store(status::waiting); _status.store(status::waiting);
wake(); wake();
......
...@@ -142,8 +142,8 @@ public: ...@@ -142,8 +142,8 @@ public:
}; };
struct attr { struct attr {
stack_info stack; stack_info stack;
bool pinned; cpu *pinned_cpu;
attr(bool pinned = false) : pinned(pinned) { } attr(cpu *pinned_cpu = nullptr) : pinned_cpu(pinned_cpu) { }
}; };
public: public:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment