Skip to contentSkip to conversation

check if set_schedaffinity works in configure.ac

RFC PATCH Pranith Kumar 3 participants 5 messages Jun 8, 2014 – Jul 11, 2014 4 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 3 lines · Pranith Kumar

On some systems set_schedaffinity exists but return "-1" when called. Tests fail in such cases ("test_urcu_hash")

Check if we can call set_schedaffinity and define accordingly

I just realized that this is a common mailing list. This is for userspace-rcu library. I am trying to use it on an Nvidia Tegra K1 device.

Quoted 66 lines
---
 configure.ac | 37 +++++++++++++++++++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)
configure.ac +35 -2
index 008336c..3074bbc 100644
@@ -269,7 +269,7 @@ AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
 ])
 
 # First check if the function is available at all.
-AC_CHECK_FUNCS([sched_setaffinity],[
+AC_CHECK_FUNC([sched_setaffinity],[
     # Okay, we have it.  Check if also have cpu_set_t.  If we don't,
     # then we have the first version using unsigned long, and no
     # CPU_ZERO, etc. macros.  If we do have cpu_set_t, we may have the
@@ -295,12 +295,45 @@ AC_CHECK_FUNCS([sched_setaffinity],[
         [sched_set_affinity_args=2])
         AC_DEFINE_UNQUOTED(SCHED_SETAFFINITY_ARGS,
             $sched_set_affinity_args,
-            [Defined to sched_setaffinity's number of arguments.])
+            [Defined to number of arguments taken by sched_setaffinity.])
         AC_MSG_RESULT([$sched_set_affinity_args])
     ],[
         # No cpu_set_t, always 3 args.
         AC_DEFINE(SCHED_SETAFFINITY_ARGS, 3)
     ])
+    AS_IF([test "x$sched_set_affinity_args" = "x3"], [
+        # test if sched_setaffinity works
+        AC_MSG_CHECKING([if sched_setaffinity works])
+        AC_RUN_IFELSE([AC_LANG_SOURCE([[
+                #include <sched.h>
+                int main()
+                {
+                    cpu_set_t foo;
+                    return sched_setaffinity(0, sizeof (foo), &foo);
+                }
+            ]])
+        ],
+        [sched_set_affinity_works=1],
+        [sched_set_affinity_works=0])
+        AC_DEFINE_UNQUOTED(HAVE_SCHED_SETAFFINITY,
+            $sched_set_affinity_works)
+    ],[
+        # test if sched_setaffinity works
+        AC_MSG_CHECKING([if sched_setaffinity works])
+        AC_RUN_IFELSE([AC_LANG_SOURCE([[
+                #include <sched.h>
+                int main()
+                {
+                    cpu_set_t foo;
+                    return sched_setaffinity(0, &foo);
+                }
+            ]])
+        ],
+        [sched_set_affinity_works=1],
+        [sched_set_affinity_works=0])
+        AC_DEFINE_UNQUOTED(HAVE_SCHED_SETAFFINITY,
+            $sched_set_affinity_works)
+    ])
 ])
 
 CFLAGS=$saved_CFLAGS

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw
Quoted 6 lines · Pranith Kumar
Quoted 3 lines · Pranith Kumar

On some systems set_schedaffinity exists but return "-1" when called. Tests fail in such cases ("test_urcu_hash")

Check if we can call set_schedaffinity and define accordingly

I just realized that this is a common mailing list. This is for userspace-rcu library. I am trying to use it on an Nvidia Tegra K1 device.

Oops, the generated files do not work as there is a missing message. Fixed and updated the patch below:

---
 configure.ac | 39 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 37 insertions(+), 2 deletions(-)
configure.ac +37 -2
index 008336c..3df6918 100644
@@ -269,7 +269,7 @@ AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
 ])
 
 # First check if the function is available at all.
-AC_CHECK_FUNCS([sched_setaffinity],[
+AC_CHECK_FUNC([sched_setaffinity],[
     # Okay, we have it.  Check if also have cpu_set_t.  If we don't,
     # then we have the first version using unsigned long, and no
     # CPU_ZERO, etc. macros.  If we do have cpu_set_t, we may have the
@@ -295,12 +295,47 @@ AC_CHECK_FUNCS([sched_setaffinity],[
         [sched_set_affinity_args=2])
         AC_DEFINE_UNQUOTED(SCHED_SETAFFINITY_ARGS,
             $sched_set_affinity_args,
-            [Defined to sched_setaffinity's number of arguments.])
+            [Defined to number of arguments taken by sched_setaffinity.])
         AC_MSG_RESULT([$sched_set_affinity_args])
     ],[
         # No cpu_set_t, always 3 args.
         AC_DEFINE(SCHED_SETAFFINITY_ARGS, 3)
     ])
+    AS_IF([test "x$sched_set_affinity_args" = "x3"], [
+        # test if sched_setaffinity works
+        AC_MSG_CHECKING([if sched_setaffinity works])
+        AC_RUN_IFELSE([AC_LANG_SOURCE([[
+                #include <sched.h>
+                int main()
+                {
+                    cpu_set_t foo;
+                    return sched_setaffinity(0, sizeof (foo), &foo);
+                }
+            ]])
+        ],
+        [sched_set_affinity_works=1],
+        [sched_set_affinity_works=0])
+        AC_DEFINE_UNQUOTED(HAVE_SCHED_SETAFFINITY,
+            $sched_set_affinity_works,
+            [Defined if sched_setaffinity works])
+    ],[
+        # test if sched_setaffinity works
+        AC_MSG_CHECKING([if sched_setaffinity works])
+        AC_RUN_IFELSE([AC_LANG_SOURCE([[
+                #include <sched.h>
+                int main()
+                {
+                    cpu_set_t foo;
+                    return sched_setaffinity(0, &foo);
+                }
+            ]])
+        ],
+        [sched_set_affinity_works=1],
+        [sched_set_affinity_works=0])
+        AC_DEFINE_UNQUOTED(HAVE_SCHED_SETAFFINITY,
+            $sched_set_affinity_works,
+            [Defined if sched_setaffinity works])
+    ])
 ])
 
 CFLAGS=$saved_CFLAGS
Signature · 1 line
1.9.1
#4 lore raw
In reply to a message not in the archive
Quoted 8 lines · Pranith Kumar
Quoted 4 lines · Pranith Kumar

On some systems set_schedaffinity exists but return "-1" when called. Tests fail in such cases ("test_urcu_hash")

Check if we can call set_schedaffinity and define accordingly

I just realized that this is a common mailing list. This is for userspace-rcu library. I am trying to use it on an Nvidia Tegra K1 device.

It seems odd that sched_setaffinity would fail... what is the value of errno associated with the failed calls?

(Also, you have the name of the function right in your patch, but need to correct it in the patch subject and description -- "sched_setaffinity" not "set_schedaffinity".)

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw

Review

Quoted 9 lines · Pranith Kumar
(quoted diff) +9 -0
+    AS_IF([test "x$sched_set_affinity_args" = "x3"], [
+        # test if sched_setaffinity works
+        AC_MSG_CHECKING([if sched_setaffinity works])
+        AC_RUN_IFELSE([AC_LANG_SOURCE([[
+                #include <sched.h>
+                int main()
+                {
+                    cpu_set_t foo;
+                    return sched_setaffinity(0, sizeof (foo), &foo);

This passes uninitialized stack memory to the system call; the return value is unpredictable.

If it turns out that such a test is necessary, it should probably call sched_getaffinity first and pass the result to sched_setaffinity.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#8 lore raw

----- Original Message -----

Quoted 17 lines

From: "Nathan Lynch" <[email protected]>
To: "Pranith Kumar" <[email protected]>
Cc: "mathieu desnoyers" <[email protected]>, [email protected]
Sent: Monday, June 9, 2014 2:59:56 PM
Subject: Re: [lttng-dev] [RFC PATCH 1/1] check if set_schedaffinity works in configure.ac

Review

Quoted 9 lines · Pranith Kumar
(quoted diff) +9 -0
+    AS_IF([test "x$sched_set_affinity_args" = "x3"], [
+        # test if sched_setaffinity works
+        AC_MSG_CHECKING([if sched_setaffinity works])
+        AC_RUN_IFELSE([AC_LANG_SOURCE([[
+                #include <sched.h>
+                int main()
+                {
+                    cpu_set_t foo;
+                    return sched_setaffinity(0, sizeof (foo), &foo);
Quoted 6 lines

This passes uninitialized stack memory to the system call; the return value is unpredictable.

If it turns out that such a test is necessary, it should probably call sched_getaffinity first and pass the result to sched_setaffinity.

It looks like a respin of the patch taking care of Nathan's comments is needed here. It might be a good thing to open a bug report against Userspace RCU on http://bugs.lttng.org to keep track of this issue.

Thanks!

Mathieu

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com