VirtualBox

Ignore:
Timestamp:
Nov 17, 2018 3:56:04 AM (6 years ago)
Author:
vboxsync
Message:

os2/VBoxSF: Extended VBoxSFUtil with a simple fstat() benchmark.

Location:
trunk/src/VBox/Additions/os2/VBoxSF
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/os2/VBoxSF/Makefile.kmk

    r75461 r75542  
    216216VBoxSFUtil_ASFLAGS  = -f obj -DASM_FORMAT_OMF
    217217VBoxSFUtil_INCS     = $(PATH_TOOL_OPENWATCOM)/h/os2
    218 VBoxSFUtil_LDFLAGS  = -bcl=os2v2
     218VBoxSFUtil_LDFLAGS  = -bcl=os2v2 #"IMPORT DosGlobalInfo doscalls.217"
     219VBoxSFUtil_DEFS     = $(DEFS) IN_RING3
    219220else
    220221VBoxSFUtil_TEMPLATE = VBoxGuestR3Exe
  • trunk/src/VBox/Additions/os2/VBoxSF/VBoxSFUtil.cpp

    r75461 r75542  
    3434*********************************************************************************************************************************/
    3535#include <string.h>
     36#include <stdarg.h>
    3637#include <stdio.h>
    3738#include <stdint.h>
    3839#include <stdlib.h>
    3940#define INCL_BASE
     41#define INCL_DOSINFOSEG
    4042#define OS2EMX_PLAIN_CHAR
    4143#include <os2.h>
     44#include <iprt/asm-amd64-x86.h>
    4245
    4346
     
    4750extern "C" APIRET __cdecl CallDosQFileMode(const char *pszFilename, PUSHORT pfAttr, ULONG ulReserved);
    4851
     52#ifndef GETGINFOSEG
     53typedef struct _GINFOSEG
     54{
     55    ULONG       time;
     56    ULONG       msecs;
     57    UCHAR       hour;
     58    UCHAR       minutes;
     59    UCHAR       seconds;
     60    UCHAR       hundredths;
     61    USHORT      timezone;
     62    USHORT      cusecTimerInterval;
     63    UCHAR       day;
     64    UCHAR       month;
     65    USHORT      year;
     66    UCHAR       weekday;
     67    UCHAR       uchMajorVersion;
     68    UCHAR       uchMinorVersion;
     69    UCHAR       chRevisionLetter;
     70    UCHAR       sgCurrent;
     71    UCHAR       sgMax;
     72    UCHAR       cHugeShift;
     73    UCHAR       fProtectModeOnly;
     74    USHORT      pidForeground;
     75    UCHAR       fDynamicSched;
     76    UCHAR       csecMaxWait;
     77    USHORT      cmsecMinSlice;
     78    USHORT      cmsecMaxSlice;
     79    USHORT      bootdrive;
     80    UCHAR       amecRAS[32];
     81    UCHAR       csgWindowableVioMax;
     82    UCHAR       csgPMMax;
     83    USHORT      SIS_Syslog;
     84    USHORT      SIS_MMIOBase;
     85    USHORT      SIS_MMIOAddr;
     86    UCHAR       SIS_MaxVDMs;
     87    UCHAR       SIS_Reserved;
     88} GINFOSEG;
     89typedef GINFOSEG *PGINFOSEG;
     90
     91extern "C" void _System DOS16GLOBALINFO(void);
     92# define GETGINFOSEG()      ((PGINFOSEG)(void *)(((unsigned)&DOS16GLOBALINFO & 0xfff8) << 13))
     93
     94#endif
     95
     96
     97/*********************************************************************************************************************************
     98*   Global Variables                                                                                                             *
     99*********************************************************************************************************************************/
     100static GINFOSEG volatile *g_pGInfoSeg;
     101static PTIB               g_pTib;
     102static PPIB               g_pPib;
     103
     104
     105static int syntaxError(const char *pszFormat, ...)
     106{
     107    fprintf(stderr, "syntax error: ");
     108    va_list va;
     109    va_start(va, pszFormat);
     110    vfprintf(stderr, pszFormat, va);
     111    va_end(va);
     112    if (strchr(pszFormat, '\0')[-1] != '\n')
     113        fputc('\n', stderr);
     114    return 2;
     115}
     116
     117
     118static int error(const char *pszFormat, ...)
     119{
     120    fprintf(stderr, "error: ");
     121    va_list va;
     122    va_start(va, pszFormat);
     123    vfprintf(stderr, pszFormat, va);
     124    va_end(va);
     125    if (strchr(pszFormat, '\0')[-1] != '\n')
     126        fputc('\n', stderr);
     127    return 1;
     128}
    49129
    50130
     
    55135     */
    56136    if (argc != 3)
    57     {
    58         fprintf(stderr, "syntax error: Expected three arguments to 'use' command\n");
    59         return 2;
    60     }
     137        return syntaxError("Expected three arguments to 'use' command\n");
    61138
    62139    /* The drive letter. */
     
    68145    { /* likely */ }
    69146    else
    70     {
    71         fprintf(stderr, "syntax error: Invalid drive specification '%s', expected something like 'K:'.\n", pszDrive);
    72         return 2;
    73     }
     147        return syntaxError("Invalid drive specification '%s', expected something like 'K:'.\n", pszDrive);
    74148
    75149    /* The shared folder. */
     
    79153    { /* likely */ }
    80154    else
    81     {
    82         fprintf(stderr, "syntax error: Shared folder name '%s' is too %s!\n", pszFolder, cchFolder >= 1 ? "long" : "short");
    83         return 2;
    84     }
     155        return syntaxError("Shared folder name '%s' is too %s!\n", pszFolder, cchFolder >= 1 ? "long" : "short");
    85156
    86157    /*
     
    93164        return 0;
    94165    }
    95     fprintf(stderr, "error: DosFSAttach failed: %lu\n", rc);
    96     return 1;
     166    return error("DosFSAttach failed: %lu\n", rc);
    97167}
    98168
     
    355425                    pszArg = "h";
    356426                else
    357                 {
    358                     fprintf(stderr, "syntax error: Unknown option: %s\n", argv[i]);
    359                     return 2;
    360                 }
     427                    return syntaxError("Unknown option: %s\n", argv[i]);
    361428            }
    362429            do
     
    371438                        pszValue = argv[++i];
    372439                    else
    373                     {
    374                         fprintf(stderr, "syntax error: -%c takes a value\n", chOpt);
    375                         return 2;
    376                     }
     440                        return syntaxError("-%c takes a value\n", chOpt);
    377441                    pszArg = "";
    378442                }
     
    398462                        return 0;
    399463                    default:
    400                         fprintf(stderr, "syntax error: Unknown option '%c' (%s)\n", chOpt, argv[i - (pszValue != NULL)]);
    401                         return 2;
     464                        return syntaxError("Unknown option '%c' (%s)\n", chOpt, argv[i - (pszValue != NULL)]);
    402465                }
    403466
     
    413476                pbBuf = (uint8_t *)malloc(cbBuf);
    414477                if (!pbBuf)
    415                 {
    416                     fprintf(stderr, "error: out of memory (cbBuf=%#x)\n", cbBuf);
    417                     return 1;
    418                 }
     478                    return error("out of memory (cbBuf=%#x)\n", cbBuf);
    419479            }
    420480
     
    503563
    504564
     565static int vboxSfOs2UtilBenchFStat(int argc, char **argv)
     566{
     567    int      rcRet     = 0;
     568    bool     fOptions  = true;
     569    unsigned msRuntime = 5*1000;
     570    for (int i = 1; i < argc; i++)
     571    {
     572        /*
     573         * Parse arguments.
     574         */
     575        const char *pszArg = argv[i];
     576        if (*pszArg == '-' && fOptions)
     577        {
     578            if (*++pszArg == '-')
     579            {
     580                pszArg++;
     581                if (*pszArg == '\0')
     582                {
     583                    fOptions = false;
     584                    continue;
     585                }
     586                if (strcmp(pszArg, "runtime") == 0)
     587                    pszArg = "r";
     588                else if (strcmp(pszArg, "help") == 0)
     589                    pszArg = "h";
     590                else
     591                    return syntaxError("Unknown option: %s", argv[i]);
     592            }
     593
     594            while (*pszArg != '\0')
     595            {
     596                char chOpt = *pszArg++;
     597                const char *pszValue = NULL;
     598                if (chOpt == 'r')
     599                {
     600                    if (*pszArg != '\0')
     601                    {
     602                        pszValue = *pszArg == ':' || *pszArg == '=' ? pszArg + 1 : pszArg;
     603                        pszArg = "";
     604                    }
     605                    else if (i + 1 < argc)
     606                        pszValue = argv[++i];
     607                    else
     608                        return syntaxError("Expected value after -%c.", chOpt);
     609                }
     610                switch (chOpt)
     611                {
     612                    case 'r':
     613                        msRuntime = atoi(pszValue);
     614                        break;
     615
     616                    default:
     617                        return syntaxError("Unknown option: -%c", chOpt);
     618                }
     619            }
     620        }
     621        /*
     622         * Run tests on the file.
     623         */
     624        else
     625        {
     626            ULONG ulAction = 0;
     627            HFILE hFile = NULLHANDLE;
     628            APIRET rc = DosOpen(pszArg, &hFile, &ulAction, 0 /*cbFile*/, FILE_NORMAL,
     629                                OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
     630                                OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY | OPEN_FLAGS_FAIL_ON_ERROR, NULL /*pEaBuf*/);
     631            if (rc == NO_ERROR)
     632            {
     633                /* Do a test run. */
     634                FILESTATUS3 Info;
     635                rc = DosQueryFileInfo(hFile, FIL_STANDARD, &Info, sizeof(Info));
     636                if (rc == NO_ERROR)
     637                {
     638                    printf("Testing '%s'...\n", pszArg);
     639
     640                    /* Tread water till the microsecond count changes. */
     641                    ULONG msStart = g_pGInfoSeg->msecs;
     642                    while (g_pGInfoSeg->msecs == msStart)
     643                    { /* nothing */ }
     644
     645                    /* Do the actual testing. */
     646                    msStart = g_pGInfoSeg->msecs;
     647                    ULONG    cCalls      = 0;
     648                    uint64_t cTscElapsed = ASMReadTSC();
     649                    do
     650                    {
     651                        cCalls++;
     652                        rc = DosQueryFileInfo(hFile, FIL_STANDARD, &Info, sizeof(Info));
     653                    } while (rc == NO_ERROR && g_pGInfoSeg->msecs - msStart < msRuntime );
     654                    cTscElapsed = ASMReadTSC() - cTscElapsed;
     655
     656                    if (rc == NO_ERROR)
     657                        printf("%7lu calls in %14lu ms    - %6llu ns per call\n"
     658                               "%7lu calls in %14llu ticks - %6llu ticks per call\n",
     659                               cCalls, msRuntime, msRuntime * (uint64_t)1000000 / cCalls,
     660                               cCalls, cTscElapsed, cTscElapsed / cCalls);
     661                    else
     662                        rcRet = error("DosQueryFileInfo failed on '%s' after %u calls: %u", pszArg, cCalls, rc);
     663                }
     664                else
     665                    rcRet = error("DosQueryFileInfo failed on '%s': %u", pszArg, rc);
     666                DosClose(hFile);
     667            }
     668            else
     669                rcRet = error("DosOpen failed on '%s': %u", pszArg, rc);
     670        }
     671    }
     672    return rcRet;
     673}
     674
     675
    505676int main(int argc, char **argv)
    506677{
     678    g_pGInfoSeg = GETGINFOSEG();
     679    DosGetInfoBlocks(&g_pTib, &g_pPib);
     680
    507681    /*
    508682     * Parse input.
     
    519693        if (strcmp(pszArg, "mkdir") == 0)
    520694            return vboxSfOs2UtilMkDir(argc - i, argv + i);
     695        if (strcmp(pszArg, "benchfstat") == 0)
     696            return vboxSfOs2UtilBenchFStat(argc - i, argv + i);
    521697
    522698        fprintf(stderr,  "Unknown command/option: %s\n", pszArg);
Note: See TracChangeset for help on using the changeset viewer.

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