Copilot commented on code in PR #3009:
URL: https://github.com/apache/brpc/pull/3009#discussion_r2173831313


##########
src/bthread/task_control.cpp:
##########
@@ -526,26 +533,51 @@ double TaskControl::get_cumulated_worker_time() {
     int64_t cputime_ns = 0;
     BAIDU_SCOPED_LOCK(_modify_group_mutex);
     for_each_task_group([&](TaskGroup* g) {
-        if (g) {
-            cputime_ns += g->_cumulated_cputime_ns;
-        }
+        cputime_ns += get_cumulated_worker_time(g);
     });
     return cputime_ns / 1000000000.0;
 }
 
-double TaskControl::get_cumulated_worker_time_with_tag(bthread_tag_t tag) {
+double TaskControl::get_cumulated_worker_time(bthread_tag_t tag) {
     int64_t cputime_ns = 0;
     BAIDU_SCOPED_LOCK(_modify_group_mutex);
     const size_t ngroup = tag_ngroup(tag).load(butil::memory_order_relaxed);
     auto& groups = tag_group(tag);
     for (size_t i = 0; i < ngroup; ++i) {
-        if (groups[i]) {
-            cputime_ns += groups[i]->_cumulated_cputime_ns;
-        }
+        cputime_ns += get_cumulated_worker_time(groups[i]);
     }
     return cputime_ns / 1000000000.0;
 }
 
+double TaskControl::get_cumulated_worker_time(TaskGroup* g) {
+    if (NULL == g) {
+        return 0.0;
+    }
+
+    int64_t last_run_ns = 0;
+    int64_t cputime_ns = 0;
+#if __x86_64__ || __ARM_NEON
+#ifdef __x86_64__
+    __m128i cpu_time_stat = 
_mm_load_si128(reinterpret_cast<__m128i*>(&g->_cpu_time_stat));
+#else // __ARM_NEON
+    int64x2_t cpu_time_stat = vld1q_s64(reinterpret_cast<const 
int64_t*>(&g->_cpu_time_stat));
+#endif // __x86_64__
+    last_run_ns = cpu_time_stat[0];
+    cputime_ns = cpu_time_stat[1];

Review Comment:
   [nitpick] Consider using intrinsic functions like _mm_extract_epi64 (or 
their ARM equivalents) for a clearer and more portable way of accessing 
elements of __m128i instead of relying on array-like indexing.
   ```suggestion
   #ifdef __x86_64__
       last_run_ns = _mm_extract_epi64(cpu_time_stat, 0);
       cputime_ns = _mm_extract_epi64(cpu_time_stat, 1);
   #else // __ARM_NEON
       last_run_ns = vgetq_lane_s64(cpu_time_stat, 0);
       cputime_ns = vgetq_lane_s64(cpu_time_stat, 1);
   #endif // __x86_64__
   ```



##########
src/bthread/task_group.h:
##########
@@ -248,41 +259,41 @@ friend class TaskControl;
 
     void set_pl(ParkingLot* pl) { _pl = pl; }
 
-    TaskMeta* _cur_meta;
+    TaskMeta* _cur_meta{NULL};
     
     // the control that this group belongs to
-    TaskControl* _control;
-    int _num_nosignal;
-    int _nsignaled;
-    // last scheduling time
-    int64_t _last_run_ns;
-    int64_t _cumulated_cputime_ns;
+    TaskControl* _control{NULL};

Review Comment:
   [nitpick] Prefer using nullptr instead of NULL for pointer initialization to 
better align with modern C++ practices.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to