Update to odulow per maintenance bronze
[o-du/phy.git] / fhi_lib / lib / src / xran_timer.c
index 2bee2c3..0b86f8e 100644 (file)
@@ -58,6 +58,8 @@ static struct timespec* p_last_time = &last_time;
 
 static struct timespec* p_temp_time;
 
+static struct timespec sleeptime = {.tv_nsec = 1E3 }; /* 1 us */
+
 static unsigned long current_second = 0;
 static unsigned long started_second = 0;
 static uint8_t numerlogy = 0;
@@ -117,14 +119,16 @@ void timing_adjust_gps_second(struct timespec* p_time)
 {
     struct xran_device_ctx * p_xran_dev_ctx = xran_dev_get_ctx();
 
-    long nsec = p_time->tv_nsec + p_xran_dev_ctx->offset_nsec;
-    p_time->tv_sec += p_xran_dev_ctx->offset_sec;
-    if (nsec >= 1e9)
+    if (p_time->tv_nsec >= p_xran_dev_ctx->offset_nsec)
+    {
+        p_time->tv_nsec -= p_xran_dev_ctx->offset_nsec;
+        p_time->tv_sec -= p_xran_dev_ctx->offset_sec;
+    }
+    else
     {
-        nsec -=1e9;
-        p_time->tv_sec += 1;
+        p_time->tv_nsec += 1e9 - p_xran_dev_ctx->offset_nsec;
+        p_time->tv_sec -= p_xran_dev_ctx->offset_sec + 1;
     }
-    p_time->tv_nsec = nsec;
 
     return;
 }
@@ -146,6 +150,8 @@ unsigned long get_ticks_diff(unsigned long curr_tick, unsigned long last_tick)
 long poll_next_tick(long interval_ns, unsigned long *used_tick)
 {
     struct xran_device_ctx * p_xran_dev_ctx = xran_dev_get_ctx();
+    struct xran_common_counters* pCnt = &p_xran_dev_ctx->fh_counters;
+
     long target_time;
     long delta;
     static int counter = 0;
@@ -170,9 +176,9 @@ long poll_next_tick(long interval_ns, unsigned long *used_tick)
             timing_adjust_gps_second(p_cur_time);
         delta = (p_cur_time->tv_sec * NSEC_PER_SEC + p_cur_time->tv_nsec) - target_time;
         if(delta > 0 || (delta < 0 && abs(delta) < THRESHOLD)) {
-            if (debugStop &&(debugStopCount > 0) && (tx_counter >= debugStopCount)){
+            if (debugStop &&(debugStopCount > 0) && (pCnt->tx_counter >= debugStopCount)){
                 uint64_t t1;
-                printf("STOP:[%ld.%09ld], debugStopCount %d, tx_counter %ld\n", p_cur_time->tv_sec, p_cur_time->tv_nsec, debugStopCount, tx_counter);
+                printf("STOP:[%ld.%09ld], debugStopCount %d, tx_counter %ld\n", p_cur_time->tv_sec, p_cur_time->tv_nsec, debugStopCount, pCnt->tx_counter);
                 t1 = MLogTick();
                 rte_pause();
                 MLogTask(PID_TIME_SYSTIME_STOP, t1, MLogTick());
@@ -231,12 +237,19 @@ long poll_next_tick(long interval_ns, unsigned long *used_tick)
                 uint64_t t1, t2;
                 t1 = xran_tick();
 
-                ring_processing_func();
+                if(p_xran_dev_ctx->fh_init.io_cfg.pkt_proc_core == 0)
+                    ring_processing_func();
+
                 process_dpdk_io();
 
+                /* work around for some kernel */
+                if(p_xran_dev_ctx->fh_init.io_cfg.io_sleep)
+                    nanosleep(&sleeptime,NULL);
+
                 t2 = xran_tick();
                 *used_tick += get_ticks_diff(t2, t1);
             }
+
         }
   }