Changeset 1060:13fc3fc9c789 in freeDiameter for libfdproto/fifo.c
- Timestamp:
- Apr 29, 2013, 6:15:34 PM (11 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libfdproto/fifo.c
r974 r1060 70 70 int highest;/* The highest count value for which h_cb has been called */ 71 71 int highest_ever; /* The max count value this queue has reached (for tweaking) */ 72 73 struct timespec total_time; /* Cumulated time all items spent in this queue, including blocking time (always growing, use deltas for monitoring) */ 74 struct timespec blocking_time; /* Cumulated time threads trying to post new items were blocked (queue full). */ 75 struct timespec last_time; /* For the last element retrieved from the queue, how long it take between posting (including blocking) and poping */ 76 77 }; 78 79 struct fifo_item { 80 struct fd_list item; 81 struct timespec posted_on; 72 82 }; 73 83 … … 130 140 queue->h_cb, queue->l_cb, queue->data, 131 141 queue->highest_ever); 142 fd_log_debug(" timings: total:%ld.%06ld, blocking:%ld.%06ld, last:%ld.%06ld", 143 (long)queue->total_time.tv_sec,(long)(queue->total_time.tv_nsec/1000), 144 (long)queue->blocking_time.tv_sec,(long)(queue->blocking_time.tv_nsec/1000), 145 (long)queue->last_time.tv_sec,(long)(queue->last_time.tv_nsec/1000) ); 132 146 133 147 if (dump_item) { … … 135 149 int i = 0; 136 150 for (li = queue->list.next; li != &queue->list; li = li->next) { 137 fd_log_debug(" [%i] item %p in fifo %p:", i++, li->o, queue); 138 (*dump_item)(level, li->o); 151 struct fifo_item * fi = (struct fifo_item *)li; 152 fd_log_debug(" [%i] item %p in fifo %p, posted:ld.%06ld", 153 i++, fi->item.o, queue, (long)fi->posted_on.tv_sec,(long)(fi->posted_on.tv_nsec/1000)); 154 (*dump_item)(level, fi->item.o); 139 155 } 140 156 } … … 251 267 252 268 /* Get the length of the queue */ 253 int fd_fifo_length ( struct fifo * queue, int * length )254 { 255 TRACE_ENTRY( "%p %p ", queue, length);269 int fd_fifo_length ( struct fifo * queue, int * length, int * max ) 270 { 271 TRACE_ENTRY( "%p %p %p", queue, length, max ); 256 272 257 273 /* Check the parameters */ … … 264 280 *length = queue->count; 265 281 282 if (max) 283 *max = queue->max; 284 266 285 /* Unlock */ 267 286 CHECK_POSIX( pthread_mutex_unlock( &queue->mtx ) ); … … 270 289 return 0; 271 290 } 291 292 /* Get the timings */ 293 int fd_fifo_getstats( struct fifo * queue, struct timespec * total, struct timespec * blocking, struct timespec * last) 294 { 295 TRACE_ENTRY( "%p %p %p %p", queue, total, blocking, last); 296 297 /* Check the parameters */ 298 CHECK_PARAMS( CHECK_FIFO( queue ) ); 299 300 /* lock the queue */ 301 CHECK_POSIX( pthread_mutex_lock( &queue->mtx ) ); 302 303 if (total) 304 memcpy(total, &queue->total_time, sizeof(struct timespec)); 305 306 if (blocking) 307 memcpy(blocking, &queue->blocking_time, sizeof(struct timespec)); 308 309 if (last) 310 memcpy(last, &queue->last_time, sizeof(struct timespec)); 311 312 /* Unlock */ 313 CHECK_POSIX( pthread_mutex_unlock( &queue->mtx ) ); 314 315 /* Done */ 316 return 0; 317 } 318 272 319 273 320 /* alternate version with no error checking */ … … 326 373 int fd_fifo_post_int ( struct fifo * queue, void ** item ) 327 374 { 328 struct f d_list* new;375 struct fifo_item * new; 329 376 int call_cb = 0; 377 struct timespec posted_on, queued_on; 330 378 331 379 TRACE_ENTRY( "%p %p", queue, item ); … … 333 381 /* Check the parameters */ 334 382 CHECK_PARAMS( CHECK_FIFO( queue ) && item && *item ); 383 384 /* Get the timing of this call */ 385 CHECK_SYS( clock_gettime(CLOCK_REALTIME, &posted_on) ); 335 386 336 387 /* lock the queue */ … … 353 404 354 405 /* Create a new list item */ 355 CHECK_MALLOC_DO( new = malloc (sizeof (struct f d_list)) , {406 CHECK_MALLOC_DO( new = malloc (sizeof (struct fifo_item)) , { 356 407 pthread_mutex_unlock( &queue->mtx ); 357 408 } ); 358 409 359 fd_list_init( new, *item);410 fd_list_init(&new->item, *item); 360 411 *item = NULL; 361 412 362 413 /* Add the new item at the end */ 363 fd_list_insert_before( &queue->list, new);414 fd_list_insert_before( &queue->list, &new->item); 364 415 queue->count++; 365 416 if (queue->highest_ever < queue->count) … … 370 421 } 371 422 423 /* store timing */ 424 memcpy(&new->posted_on, &posted_on, sizeof(struct timespec)); 425 426 /* update queue timing info "blocking time" */ 427 { 428 long long blocked_ns; 429 CHECK_SYS( clock_gettime(CLOCK_REALTIME, &queued_on) ); 430 blocked_ns = (queued_on.tv_sec - posted_on.tv_sec) * 1000000000; 431 blocked_ns += (queued_on.tv_nsec - posted_on.tv_nsec); 432 blocked_ns += queue->blocking_time.tv_nsec; 433 queue->blocking_time.tv_sec += blocked_ns / 1000000000; 434 queue->blocking_time.tv_nsec = blocked_ns % 1000000000; 435 } 436 372 437 /* Signal if threads are asleep */ 373 438 if (queue->thrs > 0) { … … 394 459 { 395 460 void * ret = NULL; 396 struct fd_list * li; 461 struct fifo_item * fi; 462 struct timespec now; 397 463 398 464 ASSERT( ! FD_IS_LIST_EMPTY(&queue->list) ); 399 465 400 fd_list_unlink(li = queue->list.next); 466 fi = (struct fifo_item *)queue->list.next; 467 fd_list_unlink(&fi->item); 401 468 queue->count--; 402 ret = li->o; 403 free(li); 469 ret = fi->item.o; 470 471 /* Update the timings */ 472 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &now), goto skip_timing ); 473 { 474 long long elapsed = (now.tv_sec - fi->posted_on.tv_sec) * 1000000000; 475 elapsed += now.tv_nsec - fi->posted_on.tv_nsec; 476 477 queue->last_time.tv_sec = elapsed / 1000000000; 478 queue->last_time.tv_nsec = elapsed % 1000000000; 479 480 elapsed += queue->total_time.tv_nsec; 481 queue->total_time.tv_sec += elapsed / 1000000000; 482 queue->total_time.tv_nsec = elapsed % 1000000000; 483 } 484 skip_timing: 485 free(fi); 404 486 405 487 if (queue->thrs_push) {
Note: See TracChangeset
for help on using the changeset viewer.