Changeset 7130754 in mainline


Ignore:
Timestamp:
2024-01-03T16:48:56Z (4 months ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master, topic/simplify-dev-export
Children:
de96d3b
Parents:
550ed86
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2024-01-01 21:28:44)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2024-01-03 16:48:56)
Message:

Add printbench command for benchmarking print output

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/console/cmd.c

    r550ed86 r7130754  
    229229};
    230230
     231/* Data and methods for 'printbench' command. */
     232static int cmd_printbench(cmd_arg_t *argv);
     233
     234static cmd_info_t printbench_info = {
     235        .name = "printbench",
     236        .description = "Run a printing benchmark.",
     237        .func = cmd_printbench,
     238        .argc = 0,
     239};
     240
    231241#endif /* CONFIG_TEST */
    232242
     
    613623        &test_info,
    614624        &bench_info,
     625        &printbench_info,
    615626#endif
    616627#ifdef CONFIG_UDEBUG
     
    15821593}
    15831594
     1595int cmd_printbench(cmd_arg_t *argv)
     1596{
     1597        int cnt = 20;
     1598
     1599        uint64_t *data = malloc(sizeof(uint64_t) * cnt);
     1600        if (data == NULL) {
     1601                printf("Error allocating memory for statistics\n");
     1602                return false;
     1603        }
     1604
     1605        for (int i = 0; i < cnt; i++) {
     1606                /*
     1607                 * Update and read thread accounting
     1608                 * for benchmarking
     1609                 */
     1610                irq_spinlock_lock(&TASK->lock, true);
     1611                uint64_t ucycles0, kcycles0;
     1612                task_get_accounting(TASK, &ucycles0, &kcycles0);
     1613                irq_spinlock_unlock(&TASK->lock, true);
     1614
     1615                /* Execute the test */
     1616                for (int j = 0; j < 20; j++) {
     1617                        printf("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ěščřžýáíéú!@#$%%^&*(){}+\n");
     1618                        printf("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ěščřžýáíéú!@#$%%^&*(){}+abcdefghijklmnopqrstuvwxyz\n");
     1619                        printf("0123456789ěščřžýáíéú!@#$%%^&*(){}+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\n");
     1620                }
     1621
     1622                /* Update and read thread accounting */
     1623                irq_spinlock_lock(&TASK->lock, true);
     1624                uint64_t ucycles1, kcycles1;
     1625                task_get_accounting(TASK, &ucycles1, &kcycles1);
     1626                irq_spinlock_unlock(&TASK->lock, true);
     1627
     1628                data[i] = ucycles1 - ucycles0 + kcycles1 - kcycles0;
     1629        }
     1630
     1631        printf("\n");
     1632
     1633        uint64_t cycles;
     1634        char suffix;
     1635        uint64_t sum = 0;
     1636
     1637        for (int i = 0; i < cnt; i++) {
     1638                sum += data[i];
     1639        }
     1640
     1641        order_suffix(sum / (uint64_t) cnt, &cycles, &suffix);
     1642        printf("Average\t\t%" PRIu64 "%c\n", cycles, suffix);
     1643
     1644        free(data);
     1645
     1646        return true;
     1647}
     1648
    15841649#endif
    15851650
Note: See TracChangeset for help on using the changeset viewer.