hwpmc_logging.c (147708) | hwpmc_logging.c (147867) |
---|---|
1/*- 2 * Copyright (c) 2005 Joseph Koshy 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 16 unchanged lines hidden (view full) --- 25 * 26 */ 27 28/* 29 * Logging code for hwpmc(4) 30 */ 31 32#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2005 Joseph Koshy 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 16 unchanged lines hidden (view full) --- 25 * 26 */ 27 28/* 29 * Logging code for hwpmc(4) 30 */ 31 32#include <sys/cdefs.h> |
33__FBSDID("$FreeBSD: head/sys/dev/hwpmc/hwpmc_logging.c 147708 2005-06-30 19:01:26Z jkoshy $"); | 33__FBSDID("$FreeBSD: head/sys/dev/hwpmc/hwpmc_logging.c 147867 2005-07-09 17:29:36Z jkoshy $"); |
34 35#include <sys/param.h> 36#include <sys/file.h> 37#include <sys/kernel.h> 38#include <sys/kthread.h> 39#include <sys/lock.h> 40#include <sys/module.h> 41#include <sys/mutex.h> --- 50 unchanged lines hidden (view full) --- 92 __roundup; \ 93 } while (0) 94 95 96/* 97 * Log file record constructors. 98 */ 99 | 34 35#include <sys/param.h> 36#include <sys/file.h> 37#include <sys/kernel.h> 38#include <sys/kthread.h> 39#include <sys/lock.h> 40#include <sys/module.h> 41#include <sys/mutex.h> --- 50 unchanged lines hidden (view full) --- 92 __roundup; \ 93 } while (0) 94 95 96/* 97 * Log file record constructors. 98 */ 99 |
100#define _PMCLOG_TO_HEADER(T,L) \ 101 ((PMCLOG_HEADER_MAGIC << 24) | \ 102 (PMCLOG_TYPE_ ## T << 16) | \ 103 ((L) & 0xFFFF)) 104 |
|
100/* reserve LEN bytes of space and initialize the entry header */ 101#define _PMCLOG_RESERVE(PO,TYPE,LEN,ACTION) do { \ 102 uint32_t *_le; \ 103 int _len = roundup((LEN), sizeof(uint32_t)); \ 104 if ((_le = pmclog_reserve((PO), _len)) == NULL) { \ 105 ACTION; \ 106 } \ | 105/* reserve LEN bytes of space and initialize the entry header */ 106#define _PMCLOG_RESERVE(PO,TYPE,LEN,ACTION) do { \ 107 uint32_t *_le; \ 108 int _len = roundup((LEN), sizeof(uint32_t)); \ 109 if ((_le = pmclog_reserve((PO), _len)) == NULL) { \ 110 ACTION; \ 111 } \ |
107 *_le = (PMCLOG_HEADER_MAGIC << 24) | \ 108 (PMCLOG_TYPE_ ## TYPE << 16) | \ 109 (_len & 0xFFFF); \ | 112 *_le = _PMCLOG_TO_HEADER(TYPE,_len); \ |
110 _le += 3 /* skip over timestamp */ 111 112#define PMCLOG_RESERVE(P,T,L) _PMCLOG_RESERVE(P,T,L,return) 113#define PMCLOG_RESERVE_WITH_ERROR(P,T,L) _PMCLOG_RESERVE(P,T,L, \ 114 error=ENOMEM;goto error) 115 116#define PMCLOG_EMIT32(V) do { *_le++ = (V); } while (0) 117#define PMCLOG_EMIT64(V) do { \ --- 274 unchanged lines hidden (view full) --- 392 * available. Non-null returns do so with the po mutex locked. The 393 * caller must invoke pmclog_release() on the pmc owner structure 394 * when done. 395 */ 396 397static uint32_t * 398pmclog_reserve(struct pmc_owner *po, int length) 399{ | 113 _le += 3 /* skip over timestamp */ 114 115#define PMCLOG_RESERVE(P,T,L) _PMCLOG_RESERVE(P,T,L,return) 116#define PMCLOG_RESERVE_WITH_ERROR(P,T,L) _PMCLOG_RESERVE(P,T,L, \ 117 error=ENOMEM;goto error) 118 119#define PMCLOG_EMIT32(V) do { *_le++ = (V); } while (0) 120#define PMCLOG_EMIT64(V) do { \ --- 274 unchanged lines hidden (view full) --- 395 * available. Non-null returns do so with the po mutex locked. The 396 * caller must invoke pmclog_release() on the pmc owner structure 397 * when done. 398 */ 399 400static uint32_t * 401pmclog_reserve(struct pmc_owner *po, int length) 402{ |
400 char *newptr, *oldptr; | 403 uintptr_t newptr, oldptr; |
401 uint32_t *lh; 402 struct timespec ts; 403 404 PMCDBG(LOG,ALL,1, "po=%p len=%d", po, length); 405 406 KASSERT(length % sizeof(uint32_t) == 0, 407 ("[pmclog,%d] length not a multiple of word size", __LINE__)); 408 --- 9 unchanged lines hidden (view full) --- 418 ("[pmc,%d] po=%p no current buffer", __LINE__, po)); 419 420 KASSERT(po->po_curbuf->plb_ptr >= po->po_curbuf->plb_base && 421 po->po_curbuf->plb_ptr <= po->po_curbuf->plb_fence, 422 ("[pmc,%d] po=%p buffer invariants: ptr=%p base=%p fence=%p", 423 __LINE__, po, po->po_curbuf->plb_ptr, po->po_curbuf->plb_base, 424 po->po_curbuf->plb_fence)); 425 | 404 uint32_t *lh; 405 struct timespec ts; 406 407 PMCDBG(LOG,ALL,1, "po=%p len=%d", po, length); 408 409 KASSERT(length % sizeof(uint32_t) == 0, 410 ("[pmclog,%d] length not a multiple of word size", __LINE__)); 411 --- 9 unchanged lines hidden (view full) --- 421 ("[pmc,%d] po=%p no current buffer", __LINE__, po)); 422 423 KASSERT(po->po_curbuf->plb_ptr >= po->po_curbuf->plb_base && 424 po->po_curbuf->plb_ptr <= po->po_curbuf->plb_fence, 425 ("[pmc,%d] po=%p buffer invariants: ptr=%p base=%p fence=%p", 426 __LINE__, po, po->po_curbuf->plb_ptr, po->po_curbuf->plb_base, 427 po->po_curbuf->plb_fence)); 428 |
426 oldptr = po->po_curbuf->plb_ptr; | 429 oldptr = (uintptr_t) po->po_curbuf->plb_ptr; |
427 newptr = oldptr + length; 428 | 430 newptr = oldptr + length; 431 |
429 KASSERT(oldptr != NULL, | 432 KASSERT(oldptr != (uintptr_t) NULL, |
430 ("[pmc,%d] po=%p Null log buffer pointer", __LINE__, po)); 431 432 /* 433 * If we have space in the current buffer, return a pointer to 434 * available space with the PO structure locked. 435 */ | 433 ("[pmc,%d] po=%p Null log buffer pointer", __LINE__, po)); 434 435 /* 436 * If we have space in the current buffer, return a pointer to 437 * available space with the PO structure locked. 438 */ |
436 if (newptr <= po->po_curbuf->plb_fence) { 437 po->po_curbuf->plb_ptr = newptr; | 439 if (newptr <= (uintptr_t) po->po_curbuf->plb_fence) { 440 po->po_curbuf->plb_ptr = (char *) newptr; |
438 goto done; 439 } 440 | 441 goto done; 442 } 443 |
441 /* otherwise, schedule the current buffer and get a fresh buffer */ | 444 /* 445 * Otherwise, schedule the current buffer for output and get a 446 * fresh buffer. 447 */ |
442 pmclog_schedule_io(po); 443 444 if (pmclog_get_buffer(po) != 0) { 445 mtx_unlock_spin(&po->po_mtx); 446 return NULL; 447 } 448 449 KASSERT(po->po_curbuf != NULL, 450 ("[pmc,%d] po=%p no current buffer", __LINE__, po)); 451 452 KASSERT(po->po_curbuf->plb_ptr != NULL, 453 ("[pmc,%d] null return from pmc_get_log_buffer", __LINE__)); 454 455 KASSERT(po->po_curbuf->plb_ptr == po->po_curbuf->plb_base && 456 po->po_curbuf->plb_ptr <= po->po_curbuf->plb_fence, 457 ("[pmc,%d] po=%p buffer invariants: ptr=%p base=%p fence=%p", 458 __LINE__, po, po->po_curbuf->plb_ptr, po->po_curbuf->plb_base, 459 po->po_curbuf->plb_fence)); 460 | 448 pmclog_schedule_io(po); 449 450 if (pmclog_get_buffer(po) != 0) { 451 mtx_unlock_spin(&po->po_mtx); 452 return NULL; 453 } 454 455 KASSERT(po->po_curbuf != NULL, 456 ("[pmc,%d] po=%p no current buffer", __LINE__, po)); 457 458 KASSERT(po->po_curbuf->plb_ptr != NULL, 459 ("[pmc,%d] null return from pmc_get_log_buffer", __LINE__)); 460 461 KASSERT(po->po_curbuf->plb_ptr == po->po_curbuf->plb_base && 462 po->po_curbuf->plb_ptr <= po->po_curbuf->plb_fence, 463 ("[pmc,%d] po=%p buffer invariants: ptr=%p base=%p fence=%p", 464 __LINE__, po, po->po_curbuf->plb_ptr, po->po_curbuf->plb_base, 465 po->po_curbuf->plb_fence)); 466 |
461 oldptr = po->po_curbuf->plb_ptr; | 467 oldptr = (uintptr_t) po->po_curbuf->plb_ptr; |
462 463 done: | 468 469 done: |
464 lh = (uint32_t *) oldptr; lh++; 465 /* fill in the timestamp */ 466 getnanotime(&ts); | 470 lh = (uint32_t *) oldptr; 471 lh++; /* skip header */ 472 getnanotime(&ts); /* fill in the timestamp */ |
467 *lh++ = ts.tv_sec & 0xFFFFFFFF; 468 *lh++ = ts.tv_nsec & 0xFFFFFFF; 469 return (uint32_t *) oldptr; 470} 471 472/* 473 * Schedule an I/O. 474 * --- 37 unchanged lines hidden (view full) --- 512 * Unset flag, wakeup the helper thread, 513 * wait for it to exit 514 */ 515 516 mtx_assert(&pmc_kthread_mtx, MA_OWNED); 517 po->po_flags &= ~PMC_PO_OWNS_LOGFILE; 518 wakeup_one(po); 519 if (po->po_kthread) | 473 *lh++ = ts.tv_sec & 0xFFFFFFFF; 474 *lh++ = ts.tv_nsec & 0xFFFFFFF; 475 return (uint32_t *) oldptr; 476} 477 478/* 479 * Schedule an I/O. 480 * --- 37 unchanged lines hidden (view full) --- 518 * Unset flag, wakeup the helper thread, 519 * wait for it to exit 520 */ 521 522 mtx_assert(&pmc_kthread_mtx, MA_OWNED); 523 po->po_flags &= ~PMC_PO_OWNS_LOGFILE; 524 wakeup_one(po); 525 if (po->po_kthread) |
520 msleep(po->po_kthread, &pmc_kthread_mtx, PPAUSE, "pmcdcl", 0); | 526 msleep(po->po_kthread, &pmc_kthread_mtx, PPAUSE, "pmckstp", 0); |
521} 522 523/* 524 * Public functions 525 */ 526 527/* 528 * Configure a log file for pmc owner 'po'. --- 453 unchanged lines hidden --- | 527} 528 529/* 530 * Public functions 531 */ 532 533/* 534 * Configure a log file for pmc owner 'po'. --- 453 unchanged lines hidden --- |