VirtualBox

Changeset 107958 in vbox for trunk


Ignore:
Timestamp:
Jan 28, 2025 9:28:51 AM (3 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
167206
Message:

VBoxTray/IPC: Unified logging to also use the VBoxTray logging facilities, back off a little in the main worker thread if something has failed, to not hog the CPU too much. Note: This does not fix the actual issue yet but only fixes the symptom. ticketref:22123

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxIPC.cpp

    r106466 r107958  
    4545
    4646#include "VBoxTray.h"
     47#include "VBoxTrayInternal.h"
    4748#include "VBoxTrayMsg.h"
    4849#include "VBoxHelpers.h"
     
    282283    AssertPtrReturnVoid(pvInstance);
    283284
    284     LogFlowFunc(("Stopping pvInstance=%p\n", pvInstance));
     285     VBoxTrayInfo("IPC: Stopping worker thread ...\n");
    285286
    286287    /* Shut down local IPC server. */
     
    331332        rc = RTLocalIpcServerDestroy(pCtx->hServer);
    332333        if (RT_FAILURE(rc))
    333             LogFlowFunc(("Unable to destroy IPC server, rc=%Rrc\n", rc));
     334            VBoxTrayError("IPC: Unable to destroy IPC server, rc=%Rrc\n", rc);
    334335
    335336        int rc2 = RTCritSectLeave(&pCtx->CritSect);
     
    338339    }
    339340
    340     LogFlowFunc(("Waiting for remaining IPC sessions to shut down ...\n"));
     341    VBoxTrayInfo("IPC: Waiting for remaining IPC sessions to shut down ...\n");
    341342
    342343    /* Wait for all IPC session threads to shut down. */
     
    359360    } while (!fListIsEmpty);
    360361
    361     AssertMsg(fListIsEmpty,
    362               ("Session thread list is not empty when it should\n"));
    363 
    364     LogFlowFunc(("All remaining IPC sessions shut down\n"));
     362    AssertMsg(fListIsEmpty, ("Session thread list is not empty when it should\n"));
     363    VBoxTrayInfo("IPC: All remaining IPC sessions shut down\n");
    365364
    366365    int rc2 = RTCritSectDelete(&pCtx->CritSect);
     
    368367        rc = rc2;
    369368
    370     LogFlowFunc(("Destroyed pvInstance=%p, rc=%Rrc\n",
    371              pvInstance, rc));
     369    LogFlowFunc(("Destroyed pvInstance=%p, rc=%Rrc\n", pvInstance, rc));
    372370}
    373371
     
    387385    AssertReturn(hSession != NIL_RTLOCALIPCSESSION, VERR_INVALID_PARAMETER);
    388386
    389     LogFlowFunc(("pThis=%p\n", pThis));
     387    VBoxTrayVerbose(1, "IPC: Session thread %#x started\n", hSession);
    390388
    391389    int rc = VINF_SUCCESS;
     
    419417                || Hdr.uVersion != VBOXTRAY_IPC_HDR_VERSION)
    420418            {
    421                 LogRelFunc(("Session %p: Invalid header magic/version: %#x, %#x, %#x, %#x\n",
    422                             pThis, Hdr.uMagic, Hdr.uVersion, Hdr.enmMsgType, Hdr.cbPayload));
     419                VBoxTrayVerbose(1, "IPC: Session %#x: Invalid header magic/version: %#x, %#x, %#x, %#x\n",
     420                                hSession, Hdr.uMagic, Hdr.uVersion, Hdr.enmMsgType, Hdr.cbPayload);
    423421                rc = VERR_INVALID_MAGIC;
    424422                break;
     
    426424            if (Hdr.cbPayload > VBOXTRAY_IPC_MAX_PAYLOAD)
    427425            {
    428                 LogRelFunc(("Session %p: Payload to big: %#x, %#x, %#x, %#x - max %#x\n",
    429                             pThis, Hdr.uMagic, Hdr.uVersion, Hdr.enmMsgType, Hdr.cbPayload, VBOXTRAY_IPC_MAX_PAYLOAD));
     426                VBoxTrayVerbose(1, "IPC: Session %#x: Payload too big: %#x, %#x, %#x, %#x - max %#x\n",
     427                                hSession, Hdr.uMagic, Hdr.uVersion, Hdr.enmMsgType, Hdr.cbPayload, VBOXTRAY_IPC_MAX_PAYLOAD);
    430428                rc = VERR_TOO_MUCH_DATA;
    431429                break;
     
    434432                || Hdr.enmMsgType >= VBOXTRAYIPCMSGTYPE_END)
    435433            {
    436                 LogRelFunc(("Session %p: Unknown message: %#x, %#x, %#x, %#x\n",
    437                             pThis, Hdr.uMagic, Hdr.uVersion, Hdr.enmMsgType, Hdr.cbPayload));
     434                VBoxTrayVerbose(1, "IPC: Session %#x: Unknown message: %#x, %#x, %#x, %#x\n",
     435                                hSession, Hdr.uMagic, Hdr.uVersion, Hdr.enmMsgType, Hdr.cbPayload);
    438436                rc = VERR_INVALID_FUNCTION;
    439437                break;
     
    461459            }
    462460            if (RT_FAILURE(rc))
    463                 LogFlowFunc(("Session %p: Handling command %RU32 failed with rc=%Rrc\n", pThis, Hdr.enmMsgType, rc));
     461                VBoxTrayVerbose(1, "IPC: Session %#x: Handling command %RU32 failed with rc=%Rrc\n",
     462                                hSession, Hdr.enmMsgType, rc);
    464463        }
    465464        else if (rc == VERR_CANCELLED)
    466465        {
    467             LogFlowFunc(("Session %p: Waiting for data cancelled\n", pThis));
     466            VBoxTrayVerbose(1, "IPC: Session %#x: Waiting for data cancelled\n", hSession);
    468467            rc = VINF_SUCCESS;
    469468            break;
    470469        }
    471470        else
    472             LogFlowFunc(("Session %p: Waiting for session data failed with rc=%Rrc\n", pThis, rc));
    473     }
    474 
    475     LogFlowFunc(("Session %p: Handler ended with rc=%Rrc\n", pThis, rc));
     471            VBoxTrayError("IPC: Session %#x: Waiting for session data failed with rc=%Rrc\n", hSession, rc);
     472    }
     473
     474    VBoxTrayVerbose(1, "IPC: Session thread %#x ended with rc=%Rrc\n", hSession, rc);
    476475
    477476    /*
     
    480479    int rc2 = RTLocalIpcSessionClose(hSession);
    481480    if (RT_FAILURE(rc2))
    482         LogFlowFunc(("Session %p: Failed closing session %p, rc=%Rrc\n", pThis, rc2));
     481        VBoxTrayError("IPC: Failed closing session %#x, rc=%Rrc\n", hSession, rc);
    483482
    484483    /*
     
    486485     */
    487486    PVBOXIPCCONTEXT pCtx = ASMAtomicReadPtrT(&pThis->pCtx, PVBOXIPCCONTEXT);
    488     AssertMsg(pCtx, ("Session %p: No context found\n", pThis));
     487    AssertMsg(pCtx, ("Session %#x: No context found\n", hSession));
    489488    rc2 = RTCritSectEnter(&pCtx->CritSect);
    490489    if (RT_SUCCESS(rc2))
     
    498497    }
    499498
    500     LogFlowFunc(("Session %p: Terminated with rc=%Rrc, freeing ...\n", pThis, rc));
     499    VBoxTrayVerbose(1, "IPC: Session thread %#x terminated with rc=%Rrc\n", hSession, rc);
    501500
    502501    RTMemFree(pThis);
     
    517516        if (pSession)
    518517        {
    519             pSession->pCtx      = pCtx;
     518            pSession->pCtx       = pCtx;
    520519            pSession->hSession   = hSession;
    521520            pSession->fTerminate = false;
     
    536535                int rc2 = RTLocalIpcSessionClose(hSession);
    537536                if (RT_FAILURE(rc2))
    538                     LogFlowFunc(("Failed closing session %p, rc=%Rrc\n", pSession, rc2));
    539 
    540                 LogFlowFunc(("Failed to create thread for session %p, rc=%Rrc\n", pSession, rc));
     537                    VBoxTrayError("IPC: Failed closing client session %#x with rc=%Rrc\n", hSession, rc2);
    541538                RTMemFree(pSession);
    542539            }
     
    557554
    558555    ASMAtomicWriteBool(&pSession->fTerminate, true);
     556
     557    VBoxTrayInfo("IPC: Stopping worker thread ...\n");
    559558
    560559    RTLOCALIPCSESSION hSession;
     
    567566
    568567/**
    569  * Thread function to wait for and process seamless mode change
    570  * requests
     568 * Thread worker for the IPC handling code.
    571569 */
    572570DECLCALLBACK(int) vbtrIPCWorker(void *pvInstance, bool volatile *pfShutdown)
    573571{
    574     AssertPtr(pvInstance);
    575     LogFlowFunc(("pvInstance=%p\n", pvInstance));
    576 
    577     LogFlowFuncEnter();
     572    AssertPtrReturn(pvInstance, VERR_INVALID_PARAMETER);
     573    LogFunc(("pvInstance=%p\n", pvInstance));
    578574
    579575    /*
     
    583579    RTThreadUserSignal(RTThreadSelf());
    584580
     581    VBoxTrayInfo("IPC: Worker thread started\n");
     582
    585583    PVBOXIPCCONTEXT pCtx = (PVBOXIPCCONTEXT)pvInstance;
    586584    AssertPtr(pCtx);
     
    588586    int rc;
    589587
    590     bool fShutdown = false;
    591588    for (;;)
    592589    {
     
    597594            if (rc == VERR_CANCELLED)
    598595            {
    599                 LogFlow(("Cancelled\n"));
    600                 fShutdown = true;
     596                VBoxTrayInfo("IPC: Worker thread cancelled\n");
     597                rc = VINF_SUCCESS;
     598                break;
    601599            }
    602600            else
    603                 LogRelFunc(("Listening failed with rc=%Rrc\n", rc));
    604         }
    605 
    606         if (fShutdown)
    607             break;
    608         rc = vboxIPCSessionCreate(pCtx, hClientSession);
    609         if (RT_FAILURE(rc))
    610         {
    611             LogRelFunc(("Creating new IPC server session failed with rc=%Rrc\n", rc));
    612             /* Keep going. */
     601                VBoxTrayError("IPC: Listening failed with rc=%Rrc\n", rc);
     602        }
     603        else
     604        {
     605            VBoxTrayVerbose(1, "IPC: New client connected with session %#x\n", hClientSession);
     606
     607            rc = vboxIPCSessionCreate(pCtx, hClientSession);
     608            if (RT_FAILURE(rc))
     609            {
     610                VBoxTrayError("IPC: Creating session %#x failed with rc=%Rrc\n", hClientSession, rc);
     611                /* Keep going. */
     612            }
    613613        }
    614614
    615615        if (*pfShutdown)
    616616            break;
    617     }
    618 
    619     LogFlowFuncLeaveRC(rc);
     617
     618        /* Back off a little to not hog the CPU too much. */
     619        RTThreadSleep(100 /* ms */);
     620    }
     621
     622    VBoxTrayInfo("IPC: Worker thread stopped with %Rrc\n", rc);
    620623    return rc;
    621624}
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette