--
You received this message because you are subscribed to the Google Groups "OSv Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osv-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "OSv Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osv-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
+
#ifdef __cplusplus
}
#endif
--
You received this message because you are subscribed to the Google Groups "OSv Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osv-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
This patch in itself seems reasonable, although I have to wonder why BSD used this "__size_t" instead of using "size_t" in the first place. I'm sure they had a reason, but I don't know what it was, or whether it's still relevant.
core/sched.cc | 10 ++++++++++
include/osv/sched.hh | 2 ++
2 files changed, 12 insertions(+), 0 deletions(-)
# HG changeset patch
# Date 1403286187 10800
# Fri Jun 20 14:43:07 2014 -0300
# Node ID ef68ec75e88281011a9b9e39b00de6b57cd8b7a3
# Parent 525fa25391470ef5d08fbdecdd743e4eeb1aa18f
sched: Add public interface for pinning threads to specific CPUs
For supporting pthread_setaffinity_np and pthread_getaffinity_np, we need to
support pinning threads to specific CPUs (we don't support more than pinning to
one CPU), so we need an interface for defining the pinned CPU from other parts
of the code.
diff --git a/core/sched.cc b/core/sched.cc
--- a/core/sched.cc
+++ b/core/sched.cc
@@ -1384,4 +1384,14 @@
}
+void sched::thread::set_pinned_cpu(sched::cpu *cpu)
+{
+ _attr.pin(cpu);
+}
+
+sched::cpu *sched::thread::get_pinned_cpu() const
+{
+ return _attr._pinned_cpu;
+}
+
irq_lock_type irq_lock;
diff --git a/include/osv/sched.hh b/include/osv/sched.hh
--- a/include/osv/sched.hh
+++ b/include/osv/sched.hh
@@ -441,6 +441,8 @@
void set_name(std::string name);
std::string name() const;
std::array<char, 16> name_raw() const { return _attr._name; }
+ void set_pinned_cpu(sched::cpu *);
+ sched::cpu *get_pinned_cpu() const;
/**
* Set thread's priority
*
--
You received this message because you are subscribed to the Google Groups "OSv Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osv-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "OSv Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osv-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
+
+ if (cpusetsize > sizeof(sched::max_cpus)) {
+ return EINVAL;
+ }
+ for (unsigned c = 0; c < sched::max_cpus; c++) {
+ unsigned cpuon = CPU_ISSET(c, cpuset);
+ if (cpuon) {
+ if (c > sched::cpus.size()) {
+ return EINVAL;
+ }
+ auto *cpu = sched::cpus[c];
+ pthread::from_libc(thread)->_thread.set_pinned_cpu(cpu);
+ return 0;
+ }
+ }
+ return EINVAL;
+}
+
+extern "C" int pthread_getaffinity_np(pthread_t thread, size_t cpusetsize,
+ cpuset_t *cpuset) {
+ if (cpuset == NULL) {
+ return EFAULT;
+ }
+ if (sizeof(sched::max_cpus) > cpusetsize) {
+ return EINVAL;
+ }
+ CPU_ZERO(cpuset);
+ auto *cpu = pthread::from_libc(thread)->_thread.get_pinned_cpu();
+ if (cpu != nullptr) {
+ for (unsigned int i = 0; i < sched::cpus.size(); i++) {
+ if (cpu == sched::cpus[i]) {
+ CPU_SET(i, cpuset);
+ break;
+ }
+ }
+ }
+ return 0;
+}
--
You received this message because you are subscribed to the Google Groups "OSv Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osv-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I intend to review as soon as I get back home.
Probably the second. Are we sure bsd cpuset_t is ABI equivalent to linux?
The second is probably better, I just didn't know how to proceed here.
As for the equivalence, cpu_set_t is defined as
typedef struct
{
__cpu_mask __bits[__CPU_SETSIZE / __NCPUBITS];
} cpu_set_t;
Which is similar, but not exactly equal.
But I do agree with you. Defining/importing cpu_set_t for OSv is probably better.
Best Regards,
Renato Cunha.