- Timestamp:
- 08/24/09 10:03:21 (4 years ago)
- Files:
-
- 1 modified
-
platform/mysql/mycached/trunk/picoev.h (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
platform/mysql/mycached/trunk/picoev.h
r35002 r35006 57 57 #define PICOEV_RND_UP(v, d) (((v) + (d) - 1) / (d) * (d)) 58 58 59 #define PICOEV_CACHE_LINE_SIZE 32 /* in bytes, ok if greater than the actual */ 59 60 #define PICOEV_SIMD_BITS 128 60 61 #define PICOEV_TIMEOUT_VEC_SIZE 128 … … 91 92 time_t base_time; 92 93 int resolution; 94 void* _free_addr; 93 95 } timeout; 94 96 time_t now; … … 98 100 /* read only */ 99 101 picoev_fd* fds; 102 void* _fds_free_addr; 100 103 int max_fd; 101 104 int num_loops; … … 106 109 extern picoev_globals picoev; 107 110 111 /* internal, aligned allocator */ 112 PICOEV_INLINE 113 void* picoev_memalign(size_t sz, void** orig_addr) { 114 sz = sz + PICOEV_CACHE_LINE_SIZE - 1; 115 if ((*orig_addr = malloc(sz)) == NULL) { 116 return NULL; 117 } 118 return 119 (void*)PICOEV_RND_UP((unsigned long)*orig_addr, PICOEV_CACHE_LINE_SIZE); 120 } 121 108 122 /* initializes picoev */ 109 123 PICOEV_INLINE … … 111 125 assert(! PICOEV_IS_INITED); 112 126 assert(max_fd > 0); 113 if ((picoev.fds = (picoev_fd*)valloc(sizeof(picoev_fd) * max_fd)) == NULL) { 127 if ((picoev.fds = (picoev_fd*)picoev_memalign(sizeof(picoev_fd) * max_fd, 128 &picoev._fds_free_addr)) 129 == NULL) { 114 130 return -1; 115 131 } … … 128 144 void picoev_deinit(void) { 129 145 assert(PICOEV_IS_INITED); 130 free(picoev. fds);146 free(picoev._fds_free_addr); 131 147 picoev.fds = NULL; 148 picoev._fds_free_addr = NULL; 132 149 picoev.max_fd = 0; 133 150 picoev.num_loops = 0; … … 250 267 loop->loop_id = ++picoev.num_loops; 251 268 assert(PICOEV_TOO_MANY_LOOPS); 252 /* TODO uses valloc to align memory, for future optimisation using SIMD */253 if ((loop->timeout.vec 254 = (short*)valloc((picoev.timeout_vec_size255 + picoev.timeout_vec_of_vec_size)256 * sizeof(short) * PICOEV_TIMEOUT_VEC_SIZE))269 if ((loop->timeout.vec_of_vec 270 = (short*)picoev_memalign((picoev.timeout_vec_of_vec_size 271 + picoev.timeout_vec_size) 272 * sizeof(short) * PICOEV_TIMEOUT_VEC_SIZE, 273 &loop->timeout._free_addr)) 257 274 == NULL) { 258 275 --picoev.num_loops; 259 276 return -1; 260 277 } 261 loop->timeout.vec _of_vec262 = loop->timeout.vec + picoev.timeout_vec_size * PICOEV_TIMEOUT_VEC_SIZE;278 loop->timeout.vec = loop->timeout.vec_of_vec 279 + picoev.timeout_vec_of_vec_size * PICOEV_TIMEOUT_VEC_SIZE; 263 280 loop->timeout.base_idx = 0; 264 281 loop->timeout.base_time = time(NULL); … … 272 289 PICOEV_INLINE 273 290 void picoev_deinit_loop_internal(picoev_loop* loop) { 274 free(loop->timeout. vec);291 free(loop->timeout._free_addr); 275 292 } 276 293
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)