原子操作耗时分析

本文深入探讨了在C和C++中使用原子操作的性能,通过分析`main_lock_numa.c`源码,揭示了原子操作在NUMA架构下的时间消耗,帮助开发者理解并优化多线程环境下的并发性能。
摘要由CSDN通过智能技术生成

main_lock_numa.c

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/epoll.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <sys/types.h>
#define __USE_GNU
#include <sched.h>
#include <ctype.h>
#include <pthread.h>
#include <stdbool.h>

#include "common.h"
#include "mempool.h"


#define LOOPCOUNT 0xFFFFFF

long long g_alstarttime[128];
long long g_alendtime[128];
int g_arun[128] = {
   0};
long long g_allAv[128] = {
   0};

struct testData g_stTestData = {
   0};


void * g_pbuf;


int loopht(unsigned int *puilock)
{
   
	int i;
	int iValue = 0;
	
	for(i = 0; i < LOOPCOUNT; i++)
	{
   
		(void)__sync_add_and_fetch(puilock, 1);
		//(*puilock) ++;
		//iValue = *puilock;
	}
	iValue = __sync_add_and_fetch(puilock, 1);
	return iValue;
}

void go_test(int cpucoreid)
{
   
	long long t1, t2, diff, av, pav = 0,max,min;
	int i;
    int iValue;
	unsigned int uiRWFlag = g_stTestData.uiRWFlag;
	char *pcflag;
	unsigned int uiloopcount = g_stTestData.uiLoopCount;
	unsigned int *puilock;
	
	
	if (0 == uiRWFlag)
	{
   
		pcflag = "AllLock";
		puilock = (unsigned int *)g_pbuf;
	}
	else
	{
   
		pcflag = "SelfLock";
		puilock = (unsigned int *)((unsigned char *)g_pbuf + 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值