<div dir="ltr"><div><div><div><div><div><div><div><div><div><div>Hi,<br><br></div>I am trying to create wrappers for <span class="" style="" id=":83o.1" tabindex="-1">pthreads</span> conditional variables functions (wait, signal and broadcast) to insert <span class="" style="" id=":83o.2" tabindex="-1">tracepoints</span>. I followed the same approach done for the <span class="" style="" id=":83o.3" tabindex="-1">mutex</span> functions already provided with <span class="" style="" id=":83o.4" tabindex="-1">lttng</span>, however I am running into some problems. Mainly the applications seem to get stuck when the conditional variable wrappers are enabled.<br><br></div>Here is my implementation for the wrapper functions:<br>int <span class="" style="" id=":83o.5" tabindex="-1">pthread</span>_<span class="" style="" id=":83o.6" tabindex="-1">cond</span>_wait(<span class="" style="" id=":83o.7" tabindex="-1">pthread</span>_<span class="" style="" id=":83o.8" tabindex="-1">cond</span>_t *condition, <span class="" style="" id=":83o.9" tabindex="-1">pthread</span>_<span class="" style="" id=":83o.10" tabindex="-1">mutex</span>_t *<span class="" style="" id=":83o.11" tabindex="-1">mutex</span>)                                                <br>{                                                                                                                                                                                                                                                                                                     <br>  static int (*<span class="" style="" id=":83o.12" tabindex="-1">cond</span>_wait)(<span class="" style="" id=":83o.13" tabindex="-1">pthread</span>_<span class="" style="" id=":83o.14" tabindex="-1">cond</span>_t *, <span class="" style="" id=":83o.15" tabindex="-1">pthread</span>_<span class="" style="" id=":83o.16" tabindex="-1">mutex</span>_t *);                                                         <br>  int <span class="" style="" id=":83o.17" tabindex="-1">retval</span>;                                                                                                         <br>                                                                                                                        <br>  if (!<span class="" style="" id=":83o.18" tabindex="-1">cond</span>_wait) {                                                                                                     <br>    <span class="" style="" id=":83o.19" tabindex="-1">cond</span>_wait = <span class="" style="" id=":83o.20" tabindex="-1">dlsym</span>(<span class="" style="" id=":83o.21" tabindex="-1">RTLD</span>_NEXT, "<span class="" style="" id=":83o.22" tabindex="-1">pthread</span>_<span class="" style="" id=":83o.23" tabindex="-1">cond</span>_wait");                                                                  <br>    if (!<span class="" style="" id=":83o.24" tabindex="-1">cond</span>_wait) {                                                                                                 <br>      if (thread_in_trace) {                                                                                          <br>        abort();                                                                                                      <br>      }                                                                                                               <br>      <span class="" style="" id=":83o.25" tabindex="-1">fprintf</span>(<span class="" style="" id=":83o.26" tabindex="-1">stderr</span>, "unable to initialize <span class="" style="" id=":83o.27" tabindex="-1">pthread</span> wrapper library.\n");                                             <br>      return <span class="" style="" id=":83o.28" tabindex="-1">EINVAL</span>;                                                                                                  <br>    }                                                                                                                 <br>  }                                                                                                                     <br>  if (thread_in_trace) {                                                                                              <br>    return <span class="" style="" id=":83o.29" tabindex="-1">cond</span>_wait(condition, <span class="" style="" id=":83o.30" tabindex="-1">mutex</span>);                                                                                 <br>  }                                                                                                                   <br>                                                                                                                        <br>  thread_in_trace = 1;                                                                                                <br>  <span class="" style="" id=":83o.31" tabindex="-1">tracepoint</span>(<span class="" style="" id=":83o.32" tabindex="-1">lttng</span>_<span class="" style="" id=":83o.33" tabindex="-1">ust</span>_<span class="" style="" id=":83o.34" tabindex="-1">pthread</span>, <span class="" style="" id=":83o.35" tabindex="-1">pthread</span>_<span class="" style="" id=":83o.36" tabindex="-1">cond</span>_wait_begin, condition, <span class="" style="" id=":83o.37" tabindex="-1">mutex</span>,                                            <br>    <span class="" style="" id=":83o.38" tabindex="-1">LTTNG</span>_<span class="" style="" id=":83o.39" tabindex="-1">UST</span>_CALLER_<span class="" style="" id=":83o.40" tabindex="-1">IP</span>());                                                                                           <br>  <span class="" style="" id=":83o.41" tabindex="-1">retval</span> = <span class="" style="" id=":83o.42" tabindex="-1">cond</span>_wait(condition, <span class="" style="" id=":83o.43" tabindex="-1">mutex</span>);                                                                               <br>  <span class="" style="" id=":83o.44" tabindex="-1">tracepoint</span>(<span class="" style="" id=":83o.45" tabindex="-1">lttng</span>_<span class="" style="" id=":83o.46" tabindex="-1">ust</span>_<span class="" style="" id=":83o.47" tabindex="-1">pthread</span>, <span class="" style="" id=":83o.48" tabindex="-1">pthread</span>_<span class="" style="" id=":83o.49" tabindex="-1">cond</span>_wait_end, condition, <span class="" style="" id=":83o.50" tabindex="-1">mutex</span>,                                              <br>    <span class="" style="" id=":83o.51" tabindex="-1">LTTNG</span>_<span class="" style="" id=":83o.52" tabindex="-1">UST</span>_CALLER_<span class="" style="" id=":83o.53" tabindex="-1">IP</span>());                                                                                           <br>  thread_in_trace = 0;                                                                                                <br>  return <span class="" style="" id=":83o.54" tabindex="-1">retval</span>;                                                                                                      <br>}                                                                                                                       <br>                                                                                                                        <br>int <span class="" style="" id=":83o.55" tabindex="-1">pthread</span>_<span class="" style="" id=":83o.56" tabindex="-1">cond</span>_signal(<span class="" style="" id=":83o.57" tabindex="-1">pthread</span>_<span class="" style="" id=":83o.58" tabindex="-1">cond</span>_t *condition)                                                                      <br>{                                                                                                                       <br>  static int (*<span class="" style="" id=":83o.59" tabindex="-1">cond</span>_signal)(<span class="" style="" id=":83o.60" tabindex="-1">pthread</span>_<span class="" style="" id=":83o.61" tabindex="-1">cond</span>_t *);                                                                          <br>  int <span class="" style="" id=":83o.62" tabindex="-1">retval</span>;                                                                                                           <br>                                                                                                                        <br>  if (!<span class="" style="" id=":83o.63" tabindex="-1">cond</span>_signal) {                                                                                                   <br>    <span class="" style="" id=":83o.64" tabindex="-1">cond</span>_signal = <span class="" style="" id=":83o.65" tabindex="-1">dlsym</span>(<span class="" style="" id=":83o.66" tabindex="-1">RTLD</span>_NEXT, "<span class="" style="" id=":83o.67" tabindex="-1">pthread</span>_<span class="" style="" id=":83o.68" tabindex="-1">cond</span>_signal");                                                              <br>    if (!<span class="" style="" id=":83o.69" tabindex="-1">cond</span>_signal) {                                                                                                 <br>      if (thread_in_trace) {                                                                                            <br>        abort();                                                                                                        <br>      }                                                                                                                 <br>      <span class="" style="" id=":83o.70" tabindex="-1">fprintf</span>(<span class="" style="" id=":83o.71" tabindex="-1">stderr</span>, "unable to initialize <span class="" style="" id=":83o.72" tabindex="-1">pthread</span> wrapper library.\n");                                               <br>      return <span class="" style="" id=":83o.73" tabindex="-1">EINVAL</span>;                                                                                                    <br>    }                                                                                                                   <br>  }                                                                                                                     <br>  if (thread_in_trace) {                                                                                                <br>    return <span class="" style="" id=":83o.74" tabindex="-1">cond</span>_signal(condition);                                                                                      <br>  }                                                                                                                     <br>                                                                                                                        <br>  thread_in_trace = 1;                                                                                                  <br>  <span class="" style="" id=":83o.75" tabindex="-1">tracepoint</span>(<span class="" style="" id=":83o.76" tabindex="-1">lttng</span>_<span class="" style="" id=":83o.77" tabindex="-1">ust</span>_<span class="" style="" id=":83o.78" tabindex="-1">pthread</span>, <span class="" style="" id=":83o.79" tabindex="-1">pthread</span>_<span class="" style="" id=":83o.80" tabindex="-1">cond</span>_signal_begin, condition,                                                   <br>    <span class="" style="" id=":83o.81" tabindex="-1">LTTNG</span>_<span class="" style="" id=":83o.82" tabindex="-1">UST</span>_CALLER_<span class="" style="" id=":83o.83" tabindex="-1">IP</span>());                                                                                             <br>  <span class="" style="" id=":83o.84" tabindex="-1">retval</span> = <span class="" style="" id=":83o.85" tabindex="-1">cond</span>_signal(condition);                                                                                      <br>  <span class="" style="" id=":83o.86" tabindex="-1">tracepoint</span>(<span class="" style="" id=":83o.87" tabindex="-1">lttng</span>_<span class="" style="" id=":83o.88" tabindex="-1">ust</span>_<span class="" style="" id=":83o.89" tabindex="-1">pthread</span>, <span class="" style="" id=":83o.90" tabindex="-1">pthread</span>_<span class="" style="" id=":83o.91" tabindex="-1">cond</span>_signal_end, condition,                                                     <br>    <span class="" style="" id=":83o.92" tabindex="-1">LTTNG</span>_<span class="" style="" id=":83o.93" tabindex="-1">UST</span>_CALLER_<span class="" style="" id=":83o.94" tabindex="-1">IP</span>());                                                                                             <br>  thread_in_trace = 0;                                                                                                  <br>  return <span class="" style="" id=":83o.95" tabindex="-1">retval</span>;                                                                                                        <br>}                                                                                                                       <br>                                                                                                                        <br>int <span class="" style="" id=":83o.96" tabindex="-1">pthread</span>_<span class="" style="" id=":83o.97" tabindex="-1">cond</span>_broadcast(<span class="" style="" id=":83o.98" tabindex="-1">pthread</span>_<span class="" style="" id=":83o.99" tabindex="-1">cond</span>_t *condition)                                                                   <br>{                                                                                                                       <br>  static int (*<span class="" style="" id=":83o.100" tabindex="-1">cond</span>_broadcast)(<span class="" style="" id=":83o.101" tabindex="-1">pthread</span>_<span class="" style="" id=":83o.102" tabindex="-1">cond</span>_t *);                                                                       <br>  int <span class="" style="" id=":83o.103" tabindex="-1">retval</span>;                                                                                                           <br>                                                                                                                        <br>  if (!<span class="" style="" id=":83o.104" tabindex="-1">cond</span>_broadcast) {                                                                                                <br>    <span class="" style="" id=":83o.105" tabindex="-1">cond</span>_broadcast = <span class="" style="" id=":83o.106" tabindex="-1">dlsym</span>(<span class="" style="" id=":83o.107" tabindex="-1">RTLD</span>_NEXT, "<span class="" style="" id=":83o.108" tabindex="-1">pthread</span>_<span class="" style="" id=":83o.109" tabindex="-1">cond</span>_broadcast");                                                        <br>    if (!<span class="" style="" id=":83o.110" tabindex="-1">cond</span>_broadcast) {                                                                                              <br>      if (thread_in_trace) {                                                                                            <br>        abort();                                                                                                        <br>      }                                                                                                                 <br>      <span class="" style="" id=":83o.111" tabindex="-1">fprintf</span>(<span class="" style="" id=":83o.112" tabindex="-1">stderr</span>, "unable to initialize <span class="" style="" id=":83o.113" tabindex="-1">pthread</span> wrapper library.\n");                                               <br>      return <span class="" style="" id=":83o.114" tabindex="-1">EINVAL</span>;                                                                                                    <br>    }                                                                                                                   <br>  }                                                                                                                     <br>  if (thread_in_trace) {                                                                                                <br>    return <span class="" style="" id=":83o.115" tabindex="-1">cond</span>_broadcast(condition);                                                                                   <br>  }                                                                                                                     <br>                                                                                                                        <br>  thread_in_trace = 1;                                                                                                  <br>  <span class="" style="" id=":83o.116" tabindex="-1">tracepoint</span>(<span class="" style="" id=":83o.117" tabindex="-1">lttng</span>_<span class="" style="" id=":83o.118" tabindex="-1">ust</span>_<span class="" style="" id=":83o.119" tabindex="-1">pthread</span>, <span class="" style="" id=":83o.120" tabindex="-1">pthread</span>_<span class="" style="" id=":83o.121" tabindex="-1">cond</span>_broadcast_begin, condition,                                                <br>    <span class="" style="" id=":83o.122" tabindex="-1">LTTNG</span>_<span class="" style="" id=":83o.123" tabindex="-1">UST</span>_CALLER_<span class="" style="" id=":83o.124" tabindex="-1">IP</span>());                                                                                             <br>  <span class="" style="" id=":83o.125" tabindex="-1">retval</span> = <span class="" style="" id=":83o.126" tabindex="-1">cond</span>_broadcast(condition);                                                                                   <br>  <span class="" style="" id=":83o.127" tabindex="-1">tracepoint</span>(<span class="" style="" id=":83o.128" tabindex="-1">lttng</span>_<span class="" style="" id=":83o.129" tabindex="-1">ust</span>_<span class="" style="" id=":83o.130" tabindex="-1">pthread</span>, <span class="" style="" id=":83o.131" tabindex="-1">pthread</span>_<span class="" style="" id=":83o.132" tabindex="-1">cond</span>_broadcast_end, condition,                                                  <br>    <span class="" style="" id=":83o.133" tabindex="-1">LTTNG</span>_<span class="" style="" id=":83o.134" tabindex="-1">UST</span>_CALLER_<span class="" style="" id=":83o.135" tabindex="-1">IP</span>());                                                                                             <br>  thread_in_trace = 0;                                                                                                  <br>  return <span class="" style="" id=":83o.136" tabindex="-1">retval</span>;                                                                                                        <br>}   <br><br></div>Things I have tried:<br></div>1- Comment out <span class="" style="" id=":83o.137" tabindex="-1">pthread</span>_<span class="" style="" id=":83o.138" tabindex="-1">cond</span>_wait function --> segmentation fault<br></div>2- Comment out <span class="" style="" id=":83o.139" tabindex="-1">pthread</span>_<span class="" style="" id=":83o.140" tabindex="-1">cond</span>_signal and _broadcast --> stuck (I can see the  program is still running but nor forward progress is being made) compared to the case when the wrappers are not preloaded.<br></div>3- Comment out all <span class="" style="" id=":83o.141" tabindex="-1">tracepoint</span> related code (basically the wrapper just call the corresponding <span class="" style="" id=":83o.142" tabindex="-1">pthreads</span> function) --> same results as points 1 and 2.<br><br></div>Any idea what might be causing this or how I could debug this problem?<br><br></div>Thank you very much in advance.<br><br></div>Best Regards,<br></div><span class="" style="" id=":83o.143" tabindex="-1">Shehab</span><br><div><div><div><div><div><div><div><div><div><br></div></div></div></div></div></div></div></div></div></div>