Multi-core Hash Joins
Main-memory hash join implementations for multi-core CPUs
cpu_mapping.c
1/* @version $Id: cpu_mapping.c 4548 2013-12-07 16:05:16Z bcagri $ */
2
3#include <stdio.h> /* FILE, fopen */
4#include <stdlib.h> /* exit, perror */
5#include <unistd.h> /* sysconf */
6#include <numaif.h> /* get_mempolicy() */
7
8#include "cpu_mapping.h"
9
14#define MAX_NODES 512
15
16#ifdef __cplusplus
17namespace eth_hashjoin {
18#endif // __cplusplus
19
20static int inited = 0;
21static int max_cpus;
22static int node_mapping[MAX_NODES];
23
28static int
29init_mappings_from_file()
30{
31 FILE * cfg;
32 int i;
33
34 cfg = fopen(CUSTOM_CPU_MAPPING, "r");
35 if (cfg!=NULL) {
36 if(fscanf(cfg, "%d", &max_cpus) <= 0) {
37 perror("Could not parse input!\n");
38 }
39
40 for(i = 0; i < max_cpus; i++){
41 if(fscanf(cfg, "%d", &node_mapping[i]) <= 0) {
42 perror("Could not parse input!\n");
43 }
44 }
45
46 fclose(cfg);
47 return 1;
48 }
49
50
51 /* perror("Custom cpu mapping file not found!\n"); */
52 return 0;
53}
54
59static void
60init_mappings()
61{
62 if( init_mappings_from_file() == 0 ) {
63 int i;
64
65 max_cpus = sysconf(_SC_NPROCESSORS_ONLN);
66 for(i = 0; i < max_cpus; i++){
67 node_mapping[i] = i;
68 }
69 }
70}
71
77int
78get_cpu_id(int thread_id)
79{
80 if(!inited){
81 init_mappings();
82 inited = 1;
83 }
84
85 return node_mapping[thread_id % max_cpus];
86}
87
88/* TODO: These are just place-holder implementations. */
96#define INTEL_E5 1
97
98static int numa[][16] = {
99 {0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60},
100 {1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61},
101 {2, 6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58, 62},
102 {3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 43, 47, 51, 55, 59, 63} };
103
104int
105get_numa_id(int mytid)
106{
107#if INTEL_E5
108 int ret = 0;
109
110 for(int i = 0; i < 4; i++)
111 for(int j = 0; j < 16; j++)
112 if(numa[i][j] == mytid){
113 ret = i;
114 break;
115 }
116
117 return ret;
118#else
119 return 0;
120#endif
121}
122
123int
125{
126 /* TODO: FIXME automate it from the system config. */
127#if INTEL_E5
128 return 4;
129#else
130 return 1;
131#endif
132}
133
134int
136{
137 int numa_node = -1;
138 get_mempolicy(&numa_node, NULL, 0, ptr, MPOL_F_NODE | MPOL_F_ADDR);
139 return numa_node;
140}
141
142#ifdef __cplusplus
143} // namespace eth_hashjoin
144#endif // __cplusplus
Provides cpu mapping utility function.
int get_num_numa_regions(void)
Definition: cpu_mapping.c:124
int get_numa_node_of_address(void *ptr)
Definition: cpu_mapping.c:135
#define CUSTOM_CPU_MAPPING
Definition: cpu_mapping.h:24
int get_cpu_id(int thread_id)
Definition: cpu_mapping.c:78
int get_numa_id(int mytid)
Definition: cpu_mapping.c:105
A wrapper file ensuring 64bit key size.
Definition: generator64.hpp:10