火焰图debug sysbench test

最近工作的时候发现一个问题:测试在跑sysbench threads的时候,发现小核所用的时间远远小于大核(小核cpu0~cpu5,大核cpu6~cpu7)。

小核只需要12.59s跑完以上测试,而大核却需要192s。

taskset -c 7 ./sysbench --test=threads run

Running the test with following options:
Number of threads: 1
Random number generator seed is 0 and will be ignored
Threads started!
General statistics:
   total time:                          192.2824s
   total number of events:              10000
   total time taken by event execution: 192.2422s
   response time:
        min:                                 18.75ms
        avg:                                 19.22ms
        max:                                 21.88ms
        approx.  95 percentile:              19.33ms

Threads fairness:
   events (avg/stddev):           10000.0000/0.00
   execution time (avg/stddev):   192.2422/0.00

taskset -c 3 ./sysbench --test=threads run

sysbench:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 1
Random number generator seed is 0 and will be ignored

Threads started!

General statistics:
    total time:                          12.9314s
    total number of events:              10000
    total time taken by event execution: 12.9174s
    response time:
         min:                                  1.25ms
         avg:                                  1.29ms
         max:                                  1.53ms
         approx.  95 percentile:               1.31ms

Threads fairness:
    events (avg/stddev):           10000.0000/0.00
    execution time (avg/stddev):   12.9174/0.00

1.sysbench 介绍

GitHub - akopytov/sysbench: Scriptable database and system performance benchmark

上述的taskset -c 7 ./sysbench --test=threads run 最终会使用到:

int threads_execute_event(sb_event_t *sb_req, int thread_id)
{
  unsigned int         i;
  sb_threads_request_t *threads_req = &sb_req->u.threads_request;

  (void) thread_id; /* unused */

  for(i = 0; i < thread_yields; i++)
  {
    pthread_mutex_lock(&test_mutexes[threads_req->lock_num]);
    YIELD();
    pthread_mutex_unlock(&test_mutexes[threads_req->lock_num]);
  }

  return 0;
}

这里面涉及到这yield的操作了。

2.yield操作

在操作系统内核中,YIELD()是一种机制,用于主动放弃当前线程的 CPU 时间片,从而允许其他线程运行。它通常被用来优化调度器的行为,在某些情况下可以减少不必要的上下文切换开销。

在 Linux 内核中,YIELD()并不是一个独立的函数名称,而是通过 schedule() 或者类似的调度接口来间接实现。以下是其核心逻辑:

  • 当一个线程调用了类似于 yield 的行为时,该线程会被标记为可运行状态并重新加入就绪队列。

  • 随后,调度程序会选择另一个合适的线程继续执行,而不是强制让当前线程保持占用 CPU。

3.使用火焰图分析

从火焰图中也可以看出big core 上的__shed_yield 时间消耗的比较多。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值