Changeset 38492 in vbox
- Timestamp:
- Aug 19, 2011 3:24:58 AM (13 years ago)
- Location:
- trunk/src/VBox/Devices/Network/slirp
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/slirp/debug.c
r37938 r38492 30 30 #include <iprt/string.h> 31 31 #include <iprt/stream.h> 32 #include <iprt/critsect.h> 33 #include "zone.h" 32 34 33 35 #ifdef DEBUG … … 362 364 } 363 365 366 /* 367 * Prints zone state 368 */ 369 static DECLCALLBACK(size_t) 370 printMbufZone(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput, 371 const char *pszType, void const *pvValue, 372 int cchWidth, int cchPrecision, unsigned fFlags, 373 void *pvUser) 374 { 375 size_t cb = 0; 376 const uma_zone_t zone = (const uma_zone_t)pvValue; 377 AssertReturn(RTStrCmp(pszType, "mzone") == 0, 0); 378 if (!zone) 379 cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "[zone:NULL]"); 380 else 381 cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "[zone:%p name:%s, master_zone:%R[mzone]]", 382 zone, zone->name, zone->master_zone); 383 return cb; 384 } 385 386 /* 387 * Prints zone's item state 388 */ 389 static DECLCALLBACK(size_t) 390 printMbufZoneItem(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput, 391 const char *pszType, void const *pvValue, 392 int cchWidth, int cchPrecision, unsigned fFlags, 393 void *pvUser) 394 { 395 size_t cb = 0; 396 const struct item *it = (const struct item *)pvValue; 397 AssertReturn(RTStrCmp(pszType, "mzoneitem") == 0, 0); 398 if (!it) 399 cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "[item:NULL]"); 400 else 401 cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "[iptem:%p ref_count:%d, zone:%R[mzone]]", 402 it, it->ref_count, it->zone); 403 return cb; 404 } 405 364 406 static DECLCALLBACK(size_t) 365 407 print_networkevents(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput, … … 420 462 { 421 463 422 rc = RTStrFormatTypeRegister("natsock", print_socket, NULL); 423 AssertRC(rc); 464 rc = RTStrFormatTypeRegister("natsock", print_socket, NULL); AssertRC(rc); 424 465 rc = RTStrFormatTypeRegister("natwinnetevents", 425 print_networkevents, NULL); 426 AssertRC(rc); 427 rc = RTStrFormatTypeRegister("tcpcb793", printTcpcbRfc793, NULL); 428 AssertRC(rc); 429 rc = RTStrFormatTypeRegister("tcpseg793", printTcpSegmentRfc793, NULL); 430 AssertRC(rc); 431 rc = RTStrFormatTypeRegister("tcpstate", printTcpState, NULL); 432 AssertRC(rc); 433 rc = RTStrFormatTypeRegister("sbuf", printSbuf, NULL); 434 AssertRC(rc); 466 print_networkevents, NULL); AssertRC(rc); 467 rc = RTStrFormatTypeRegister("tcpcb793", printTcpcbRfc793, NULL); AssertRC(rc); 468 rc = RTStrFormatTypeRegister("tcpseg793", printTcpSegmentRfc793, NULL); AssertRC(rc); 469 rc = RTStrFormatTypeRegister("tcpstate", printTcpState, NULL); AssertRC(rc); 470 rc = RTStrFormatTypeRegister("sbuf", printSbuf, NULL); AssertRC(rc); 471 rc = RTStrFormatTypeRegister("mzone", printMbufZone, NULL); AssertRC(rc); 472 rc = RTStrFormatTypeRegister("mzoneitem", printMbufZoneItem, NULL); AssertRC(rc); 435 473 g_fFormatRegistered = 1; 436 474 } -
trunk/src/VBox/Devices/Network/slirp/misc.c
r35957 r38492 27 27 #define WANT_SYS_IOCTL_H 28 28 #include <slirp.h> 29 #include "zone.h" 29 30 30 31 #ifndef HAVE_INET_ATON … … 97 98 98 99 99 #define ITEM_MAGIC 0xdead0001100 struct item101 {102 uint32_t magic;103 uma_zone_t zone;104 uint32_t ref_count;105 LIST_ENTRY(item) list;106 };107 108 #define ZONE_MAGIC 0xdead0002109 struct uma_zone110 {111 uint32_t magic;112 PNATState pData; /* to minimize changes in the rest of UMA emulation code */113 RTCRITSECT csZone;114 const char *name;115 size_t size; /* item size */116 ctor_t pfCtor;117 dtor_t pfDtor;118 zinit_t pfInit;119 zfini_t pfFini;120 uma_alloc_t pfAlloc;121 uma_free_t pfFree;122 int max_items;123 int cur_items;124 LIST_HEAD(RT_NOTHING, item) used_items;125 LIST_HEAD(RT_NOTHING, item) free_items;126 uma_zone_t master_zone;127 void *area;128 /** Needs call pfnXmitPending when memory becomes available if @c true.129 * @remarks Only applies to the master zone (master_zone == NULL) */130 bool fDoXmitPending;131 };132 100 133 101 … … 143 111 DECLINLINE(void) slirp_zone_check_and_send_pending(uma_zone_t zone) 144 112 { 113 LogFlowFunc(("ENTER: zone:%R[mzone]\n", zone)); 145 114 if ( zone->fDoXmitPending 146 115 && zone->master_zone == NULL) … … 154 123 rc2 = RTCritSectEnter(&zone->csZone); AssertRC(rc2); 155 124 } 125 LogFlowFuncLeave(); 156 126 } 157 127 … … 164 134 int rc; 165 135 136 LogFlowFunc(("ENTER: %R[mzone], size:%d, pflags:%p, %RTbool\n", zone, size, pflags, fWait)); 166 137 RTCritSectEnter(&zone->csZone); 167 138 for (;;) … … 229 200 } 230 201 RTCritSectLeave(&zone->csZone); 202 LogFlowFunc(("LEAVE: %p\n", ret)); 231 203 return ret; 232 204 } … … 240 212 Assert(item); 241 213 it = &((struct item *)item)[-1]; 214 LogFlowFunc(("ENTER: item:%p(%R[mzoneitem]), size:%d, flags:%RX8\n", item, it, size, flags)); 242 215 Assert(it->magic == ITEM_MAGIC); 243 216 zone = it->zone; … … 260 233 slirp_zone_check_and_send_pending(zone); /* may exit+enter the cs! */ 261 234 RTCritSectLeave(&zone->csZone); 235 LogFlowFuncLeave(); 262 236 } 263 237 … … 265 239 ctor_t ctor, dtor_t dtor, zinit_t init, zfini_t fini, int flags1, int flags2) 266 240 { 267 uma_zone_t zone = RTMemAllocZ(sizeof(struct uma_zone)); 241 uma_zone_t zone = NULL; 242 LogFlowFunc(("ENTER: name:%s size:%d, ctor:%p, dtor:%p, init:%p, fini:%p, flags1:%RX32, flags2:%RX32\n", 243 name, ctor, dtor, init, fini, flags1, flags2)); 244 zone = RTMemAllocZ(sizeof(struct uma_zone)); 268 245 Assert((pData)); 269 246 zone->magic = ZONE_MAGIC; … … 278 255 zone->pfFree = slirp_uma_free; 279 256 RTCritSectInit(&zone->csZone); 257 LogFlowFunc(("LEAVE: %R[mzone]\n", zone)); 280 258 return zone; 281 259 … … 286 264 uma_zone_t zone; 287 265 Assert(master); 266 LogFlowFunc(("ENTER: name:%s ctor:%p, dtor:%p, init:%p, fini:%p, master:%R[mzone]\n", 267 name, ctor, dtor, init, fini, master)); 288 268 zone = RTMemAllocZ(sizeof(struct uma_zone)); 289 269 if (zone == NULL) 270 { 271 LogFlowFunc(("LEAVE: %R[mzone]\n", NULL)); 290 272 return NULL; 273 } 291 274 292 275 Assert((master && master->pData)); … … 303 286 zone->master_zone = master; 304 287 RTCritSectInit(&zone->csZone); 288 LogFlowFunc(("LEAVE: %R[mzone]\n", zone)); 305 289 return zone; 306 290 } … … 310 294 int i = 0; 311 295 struct item *it; 296 LogFlowFunc(("ENTER: zone:%R[mzone], max:%d\n", zone, max)); 312 297 zone->max_items = max; 313 298 zone->area = RTMemAllocZ(max * (sizeof(struct item) + zone->size + sizeof(uint32_t))); … … 320 305 LIST_INSERT_HEAD(&zone->free_items, it, list); 321 306 } 322 307 LogFlowFuncLeave(); 323 308 } 324 309 325 310 void uma_zone_set_allocf(uma_zone_t zone, uma_alloc_t pfAlloc) 326 311 { 327 zone->pfAlloc = pfAlloc; 312 LogFlowFunc(("ENTER: zone:%R[mzone], pfAlloc:%Rfn\n", zone, pfAlloc)); 313 zone->pfAlloc = pfAlloc; 314 LogFlowFuncLeave(); 328 315 } 329 316 330 317 void uma_zone_set_freef(uma_zone_t zone, uma_free_t pfFree) 331 318 { 332 zone->pfFree = pfFree; 319 LogFlowFunc(("ENTER: zone:%R[mzone], pfAlloc:%Rfn\n", zone, pfFree)); 320 zone->pfFree = pfFree; 321 LogFlowFuncLeave(); 333 322 } 334 323 … … 337 326 /** @todo (vvl) this function supposed to work with special zone storing 338 327 reference counters */ 339 struct item *it = (struct item *)mem; /* 1st element */ 328 struct item *it = NULL; 329 LogFlowFunc(("ENTER: zone:%R[mzone], mem:%p\n", zone, mem)); 330 it = (struct item *)mem; /* 1st element */ 340 331 Assert(mem != NULL); 341 332 Assert(zone->magic == ZONE_MAGIC); 342 333 /* for returning pointer to counter we need get 0 elemnt */ 343 334 Assert(it[-1].magic == ITEM_MAGIC); 335 LogFlowFunc(("LEAVE: %p\n", &it[-1].ref_count)); 344 336 return &it[-1].ref_count; 345 337 } … … 349 341 void *mem; 350 342 Assert(zone->magic == ZONE_MAGIC); 343 LogFlowFunc(("ENTER: zone:%R[mzone], args:%p, how:%RX32\n", zone, args, how)); 351 344 if (zone->pfAlloc == NULL) 345 { 346 LogFlowFunc(("LEAVE: NULL\n")); 352 347 return NULL; 348 } 353 349 RTCritSectEnter(&zone->csZone); 354 350 mem = zone->pfAlloc(zone, zone->size, NULL, 0); … … 359 355 } 360 356 RTCritSectLeave(&zone->csZone); 357 LogFlowFunc(("LEAVE: %p\n", mem)); 361 358 return mem; 362 359 } … … 364 361 void uma_zfree(uma_zone_t zone, void *item) 365 362 { 363 LogFlowFunc(("ENTER: zone:%R[mzone], item:%p\n", zone, item)); 366 364 uma_zfree_arg(zone, item, NULL); 365 LogFlowFuncLeave(); 367 366 } 368 367 … … 373 372 Assert((zone->pfFree)); 374 373 Assert((mem)); 374 LogFlowFunc(("ENTER: zone:%R[mzone], mem:%p, flags:%p\n", zone, mem, flags)); 375 375 376 376 RTCritSectEnter(&zone->csZone); … … 381 381 zone->pfFree(mem, 0, 0); 382 382 RTCritSectLeave(&zone->csZone); 383 LogFlowFuncLeave(); 383 384 } 384 385 … … 386 387 { 387 388 int fExhausted; 389 LogFlowFunc(("ENTER: zone:%R[mzone]\n", zone)); 388 390 RTCritSectEnter(&zone->csZone); 389 391 fExhausted = (zone->cur_items == zone->max_items); 390 392 RTCritSectLeave(&zone->csZone); 393 LogFlowFunc(("LEAVE: %RTbool\n", fExhausted)); 391 394 return fExhausted; 392 395 } … … 399 402 /* vvl: Huh? What to do with zone which hasn't got backstore ? */ 400 403 Assert((zone->master_zone)); 404 LogFlowFunc(("ENTER: zone:%R[mzone]\n", zone)); 401 405 master_zone = zone->master_zone; 402 406 while (!LIST_EMPTY(&zone->free_items)) … … 418 422 RTCritSectLeave(&master_zone->csZone); 419 423 } 424 LogFlowFuncLeave(); 420 425 } 421 426 … … 423 428 { 424 429 /** @todo (vvl) make it wiser */ 430 LogFlowFunc(("ENTER: mem:%p, arg:%p\n", mem, arg)); 425 431 Assert(mem); 426 432 RTMemFree(mem); 433 LogFlowFuncLeave(); 427 434 } 428 435 429 436 void *uma_zalloc(uma_zone_t zone, int len) 430 437 { 438 LogFlowFunc(("ENTER: zone:%R[mzone], len:%d\n", zone, len)); 439 LogFlowFunc(("LEAVE: NULL")); 431 440 return NULL; 432 441 } … … 436 445 struct mbuf *m; 437 446 size_t size = MCLBYTES; 447 LogFlowFunc(("ENTER: cbMin:%d, ppvBuf:%p, pcbBuf:%p\n", cbMin, ppvBuf, pcbBuf)); 438 448 if (cbMin < MSIZE) 439 449 size = MCLBYTES; … … 452 462 *ppvBuf = NULL; 453 463 *pcbBuf = 0; 464 LogFlowFunc(("LEAVE: NULL\n")); 454 465 return NULL; 455 466 } … … 457 468 *ppvBuf = mtod(m, void *); 458 469 *pcbBuf = size; 470 LogFlowFunc(("LEAVE: %p\n", m)); 459 471 return m; 460 472 } … … 463 475 { 464 476 477 LogFlowFunc(("ENTER: m:%p, pu8Buf:%p\n", m, pu8Buf)); 465 478 if ( !pu8Buf 466 479 && pu8Buf != mtod(m, uint8_t *)) 467 480 RTMemFree(pu8Buf); /* This buffer was allocated on heap */ 468 481 m_freem(pData, m); 482 LogFlowFuncLeave(); 469 483 } 470 484 … … 472 486 { 473 487 RTCritSectEnter(&zone->csZone); 488 LogFlowFunc(("ENTER: zone:%R[mzone]\n", zone)); 474 489 LogRel(("NAT: zone(nm:%s, used:%d)\n", zone->name, zone->cur_items)); 475 490 if (zone->master_zone) … … 478 493 RTCritSectDelete(&zone->csZone); 479 494 RTMemFree(zone); 495 LogFlowFuncLeave(); 480 496 } 481 497 482 498 void m_fini(PNATState pData) 483 499 { 500 LogFlowFuncEnter(); 484 501 zone_destroy(pData->zone_mbuf); 485 502 zone_destroy(pData->zone_clust); … … 489 506 zone_destroy(pData->zone_jumbo16); 490 507 /** @todo do finalize here.*/ 508 LogFlowFuncLeave(); 491 509 } 492 510 -
trunk/src/VBox/Devices/Network/slirp/misc.h
r30016 r38492 44 44 struct uma_zone; 45 45 typedef struct uma_zone *uma_zone_t; 46 46 47 typedef void *(*uma_alloc_t)(uma_zone_t, int, u_int8_t *, int); 47 48 typedef void (*uma_free_t)(void *, int, u_int8_t);
Note:
See TracChangeset
for help on using the changeset viewer.