1
1

Merge pull request #1786 from hjelmn/32_fix

opal/progress: use 32-bit atomics for call counter
Этот коммит содержится в:
Nathan Hjelm 2016-06-17 08:54:41 -06:00 коммит произвёл GitHub
родитель 2e4141f20a 7349ddc937
Коммит f59c2fce6b
2 изменённых файлов: 11 добавлений и 11 удалений

Просмотреть файл

@ -28,9 +28,9 @@
#include <dlfcn.h> #include <dlfcn.h>
#include <assert.h> #include <assert.h>
#if defined(__i386__) || defined(__x86_64__) || defined(__ia64__) #if (OPAL_ASSEMBLY_ARCH == OPAL_IA32) || (OPAL_ASSEMBLY_ARCH == OPAL_IA64) || (OPAL_ASSEMBLY_ARCH == OPAL_AMD64)
#if defined(__ia64__) #if (OPAL_ASSEMBLY_ARCH == OPAL_IA64)
#define INSERT_BIT(d,p,v) do { \ #define INSERT_BIT(d,p,v) do { \
unsigned char c=*(d); \ unsigned char c=*(d); \
@ -87,18 +87,18 @@ static int mca_patcher_overwrite_apply_patch (mca_patcher_base_patch_t *patch)
uintptr_t func_new_addr = patch->patch_value; uintptr_t func_new_addr = patch->patch_value;
{ {
#if defined(__i386__) #if (OPAL_ASSEMBLY_ARCH == OPAL_IA32)
patch->patch_data_size = 5; patch->patch_data_size = 5;
*(unsigned char *)(patch->patch_data+0) = 0xe9; *(unsigned char *)(patch->patch_data+0) = 0xe9;
*(unsigned int *) (patch->patch_data+1) = (unsigned int)(func_new_addr - patch->patch_orig - 5); *(unsigned int *) (patch->patch_data+1) = (unsigned int)(func_new_addr - patch->patch_orig - 5);
#elif defined(__x86_64__) #elif (OPAL_ASSEMBLY_ARCH == OPAL_AMD64)
patch->patch_data_size = 13; patch->patch_data_size = 13;
*(unsigned short*)(patch->patch_data + 0) = 0xbb49; *(unsigned short*)(patch->patch_data + 0) = 0xbb49;
*(unsigned long* )(patch->patch_data + 2) = (unsigned long) func_new_addr; *(unsigned long* )(patch->patch_data + 2) = (unsigned long) func_new_addr;
*(unsigned char*) (patch->patch_data +10) = 0x41; *(unsigned char*) (patch->patch_data +10) = 0x41;
*(unsigned char*) (patch->patch_data +11) = 0xff; *(unsigned char*) (patch->patch_data +11) = 0xff;
*(unsigned char*) (patch->patch_data +12) = 0xe3; *(unsigned char*) (patch->patch_data +12) = 0xe3;
#elif defined(__ia64__) #elif (OPAL_ASSEMBLY_ARCH == OPAL_IA64)
{ {
/* /*
* target64 = IP + ((i << 59 | imm39 << 20 | imm20) << 4) * target64 = IP + ((i << 59 | imm39 << 20 | imm20) << 4)
@ -155,7 +155,7 @@ static int mca_patcher_overwrite_apply_patch (mca_patcher_base_patch_t *patch)
/* end of #if defined(__i386__) || defined(__x86_64__) || defined(__ia64__) */ /* end of #if defined(__i386__) || defined(__x86_64__) || defined(__ia64__) */
// ------------------------------------------------- PPC equivalent: // ------------------------------------------------- PPC equivalent:
#elif defined(__PPC__) #elif (OPAL_ASSEMBLY_ARCH == OPAL_POWERPC32) || (OPAL_ASSEMBLY_ARCH == OPAL_POWERPC64)
// PowerPC instructions used in patching // PowerPC instructions used in patching
// Reference: "PowerPC User Instruction Set Architecture" // Reference: "PowerPC User Instruction Set Architecture"
@ -183,7 +183,7 @@ static unsigned int rldicr(unsigned int RT, unsigned int RS, unsigned int SH, un
static int static int
PatchLoadImm(uintptr_t addr, unsigned int reg, size_t value) PatchLoadImm(uintptr_t addr, unsigned int reg, size_t value)
{ {
#if defined(__PPC64__) #if (OPAL_ASSEMBLY_ARCH == OPAL_POWERPC64)
*(unsigned int *) (addr + 0) = addis ( reg, 0, (value >> 48)); *(unsigned int *) (addr + 0) = addis ( reg, 0, (value >> 48));
*(unsigned int *) (addr + 4) = ori ( reg, reg, (value >> 32)); *(unsigned int *) (addr + 4) = ori ( reg, reg, (value >> 32));
*(unsigned int *) (addr + 8) = rldicr( reg, reg, 32, 31); *(unsigned int *) (addr + 8) = rldicr( reg, reg, 32, 31);
@ -208,7 +208,7 @@ static int mca_patcher_overwrite_apply_patch (mca_patcher_base_patch_t *patch)
hook_addr = mca_patcher_base_addr_text(patch->patch_value); hook_addr = mca_patcher_base_addr_text(patch->patch_value);
// Patch for hook function: // Patch for hook function:
#if (defined(__PPC64__) || defined(__powerpc64__) || defined(__PPC__)) #if (OPAL_ASSEMBLY_ARCH == OPAL_POWERPC64)
rc = mca_patcher_base_patch_hook (&mca_patcher_overwrite_module, hook_addr); rc = mca_patcher_base_patch_hook (&mca_patcher_overwrite_module, hook_addr);
if (OPAL_SUCCESS != rc) { if (OPAL_SUCCESS != rc) {
return rc; return rc;
@ -286,7 +286,7 @@ static int mca_patcher_overwrite_patch_symbol (const char *func_symbol_name, uin
old_addr = (unsigned long)sym_addr; old_addr = (unsigned long)sym_addr;
#if defined(__ia64__) #if (OPAL_ASSEMBLY_ARCH == OPAL_IA64)
/* On IA64 addresses are all indirect */ /* On IA64 addresses are all indirect */
func_new_addr = *(unsigned long *)func_new_addr; func_new_addr = *(unsigned long *)func_new_addr;
old_addr = *(unsigned long *) old_addr; old_addr = *(unsigned long *) old_addr;

Просмотреть файл

@ -182,7 +182,7 @@ opal_progress_finalize(void)
void void
opal_progress(void) opal_progress(void)
{ {
static volatile uint64_t num_calls = 0; static volatile uint32_t num_calls = 0;
size_t i; size_t i;
int events = 0; int events = 0;
@ -221,7 +221,7 @@ opal_progress(void)
events += (callbacks[i])(); events += (callbacks[i])();
} }
if ((OPAL_THREAD_ADD64((volatile int64_t *) &num_calls, 1) & 0x7) == 0) { if ((OPAL_THREAD_ADD32((volatile int32_t *) &num_calls, 1) & 0x7) == 0) {
/* run low priority callbacks once every 8 calls to opal_progress() */ /* run low priority callbacks once every 8 calls to opal_progress() */
for (i = 0 ; i < callbacks_lp_len ; ++i) { for (i = 0 ; i < callbacks_lp_len ; ++i) {
events += (callbacks_lp[i])(); events += (callbacks_lp[i])();