title: get frequency of a clock device in Linux
body: <p>I am trying to adjust the frequency of a hardware clock device &quot;dev/ptp0&quot; in order to sync two clocks in Precision-Time-Protocol (PTP) Implementation, but the frequency doesn't seem to be adjusted synchronously as if some adjust calls are accumulated before being applied in the kernel and that is affecting my PI controller.</p>
  <p>I want to confirm the system response to my frequency adjustments, so is there a way to get the current frequency of a clock in Linux?</p>
  <p>I am using the following code to adjust/get frequency offsets but I want to get the actual frequency at the moment.</p>
  <pre><code>bool adjustFrequency(double adj)
  {   
      struct timex tmx;
      memset(&amp;tmx, 0, sizeof(tmx));
      tmx.modes = ADJ_FREQUENCY;
  
      tmx.freq = (long)(round(adj * 65.536));
      printf(&quot;setFrequency to  %lld %f\n&quot;, tmx.freq,  adj);
  
      if(clock_adjtime(clockId, &amp;tmx) &lt; 0) {
          printf(&quot;Could not adjust frequency offset of clock\n&quot;);
          return FALSE;
      }
      return TRUE
  }
  
  double getFrequency(void)
  {
      struct timex tmx;
      memset(&amp;tmx, 0, sizeof(tmx));
      if(clock_adjtime(clockId, &amp;tmx) &lt; 0) {
          printf(&quot;Could not get frequency of clock\n&quot;);
          return 0;
      }
      printf(&quot;getFrequency  %lld  %f\n&quot;,tmx.freq, (tmx.freq + 0.0) / 65.536 );
      return( (tmx.freq + 0.0) / 65.536);
  }
  </code></pre>