|
Packit Service |
b3514a |
/*
|
|
Packit Service |
b3514a |
* Copyright (c) 2020 Red Hat, Inc.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* This program is free software; you can redistribute it and/or
|
|
Packit Service |
b3514a |
* modify it under the terms of the GNU General Public License
|
|
Packit Service |
b3514a |
* as published by the Free Software Foundation; either version 2
|
|
Packit Service |
b3514a |
* of the License, or (at your option) any later version.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* This program is distributed in the hope that it will be useful,
|
|
Packit Service |
b3514a |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
b3514a |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
b3514a |
* GNU General Public License for more details.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
b3514a |
* along with this program; if not, write to the Free Software
|
|
Packit Service |
b3514a |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit Service |
b3514a |
* 02110-1301, USA.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* $Id: //eng/vdo-releases/aluminum/src/c++/vdo/kernel/workQueueStats.c#6 $
|
|
Packit Service |
b3514a |
*/
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#include "workQueueStats.h"
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#include "atomic.h"
|
|
Packit Service |
b3514a |
#include "logger.h"
|
|
Packit Service |
b3514a |
#include "workItemStats.h"
|
|
Packit Service |
b3514a |
#include "workQueueInternals.h"
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
int initializeWorkQueueStats(KvdoWorkQueueStats *stats,
|
|
Packit Service |
b3514a |
struct kobject *queueKObject)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
spin_lock_init(&stats->workItemStats.functionTable.lock);
|
|
Packit Service |
b3514a |
if (ENABLE_PER_FUNCTION_TIMING_STATS) {
|
|
Packit Service |
b3514a |
for (int i = 0; i < NUM_WORK_QUEUE_ITEM_STATS + 1; i++) {
|
|
Packit Service |
b3514a |
initSimpleStats(&stats->workItemStats.times[i]);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
stats->queueTimeHistogram
|
|
Packit Service |
b3514a |
= makeLogarithmicHistogram(queueKObject, "queue_time",
|
|
Packit Service |
b3514a |
"Queue Time", "work items", "wait time",
|
|
Packit Service |
b3514a |
"microseconds", 9);
|
|
Packit Service |
b3514a |
if (stats->queueTimeHistogram == NULL) {
|
|
Packit Service |
b3514a |
return -ENOMEM;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
stats->rescheduleQueueLengthHistogram
|
|
Packit Service |
b3514a |
= makeLogarithmicHistogram(queueKObject, "reschedule_queue_length",
|
|
Packit Service |
b3514a |
"Reschedule Queue Length", "calls",
|
|
Packit Service |
b3514a |
"queued work items", NULL, 4);
|
|
Packit Service |
b3514a |
if (stats->rescheduleQueueLengthHistogram == NULL) {
|
|
Packit Service |
b3514a |
return -ENOMEM;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
stats->rescheduleTimeHistogram
|
|
Packit Service |
b3514a |
= makeLogarithmicHistogram(queueKObject, "reschedule_time",
|
|
Packit Service |
b3514a |
"Reschedule Time", "calls",
|
|
Packit Service |
b3514a |
"sleep interval", "microseconds", 9);
|
|
Packit Service |
b3514a |
if (stats->rescheduleTimeHistogram == NULL) {
|
|
Packit Service |
b3514a |
return -ENOMEM;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
stats->runTimeBeforeRescheduleHistogram
|
|
Packit Service |
b3514a |
= makeLogarithmicHistogram(queueKObject, "run_time_before_reschedule",
|
|
Packit Service |
b3514a |
"Run Time Before Reschedule",
|
|
Packit Service |
b3514a |
"calls", "run time", "microseconds", 9);
|
|
Packit Service |
b3514a |
if (stats->runTimeBeforeRescheduleHistogram == NULL) {
|
|
Packit Service |
b3514a |
return -ENOMEM;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
stats->scheduleTimeHistogram
|
|
Packit Service |
b3514a |
= makeLogarithmicHistogram(queueKObject, "schedule_time",
|
|
Packit Service |
b3514a |
"Schedule Time",
|
|
Packit Service |
b3514a |
"calls", "sleep interval", "microseconds", 9);
|
|
Packit Service |
b3514a |
if (stats->scheduleTimeHistogram == NULL) {
|
|
Packit Service |
b3514a |
return -ENOMEM;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
stats->wakeupLatencyHistogram
|
|
Packit Service |
b3514a |
= makeLogarithmicHistogram(queueKObject, "wakeup_latency",
|
|
Packit Service |
b3514a |
"Wakeup Latency",
|
|
Packit Service |
b3514a |
"wakeups", "latency", "microseconds", 9);
|
|
Packit Service |
b3514a |
if (stats->wakeupLatencyHistogram == NULL) {
|
|
Packit Service |
b3514a |
return -ENOMEM;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
stats->wakeupQueueLengthHistogram
|
|
Packit Service |
b3514a |
= makeLogarithmicHistogram(queueKObject, "wakeup_queue_length",
|
|
Packit Service |
b3514a |
"Wakeup Queue Length", "wakeups",
|
|
Packit Service |
b3514a |
"queued work items", NULL, 4);
|
|
Packit Service |
b3514a |
if (stats->wakeupQueueLengthHistogram == NULL) {
|
|
Packit Service |
b3514a |
return -ENOMEM;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
return 0;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
void cleanupWorkQueueStats(KvdoWorkQueueStats *stats)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
freeHistogram(&stats->queueTimeHistogram);
|
|
Packit Service |
b3514a |
freeHistogram(&stats->rescheduleQueueLengthHistogram);
|
|
Packit Service |
b3514a |
freeHistogram(&stats->rescheduleTimeHistogram);
|
|
Packit Service |
b3514a |
freeHistogram(&stats->runTimeBeforeRescheduleHistogram);
|
|
Packit Service |
b3514a |
freeHistogram(&stats->scheduleTimeHistogram);
|
|
Packit Service |
b3514a |
freeHistogram(&stats->wakeupLatencyHistogram);
|
|
Packit Service |
b3514a |
freeHistogram(&stats->wakeupQueueLengthHistogram);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
static uint64_t getTotalProcessed(const SimpleWorkQueue *queue)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
uint64_t totalProcessed = 0;
|
|
Packit Service |
b3514a |
for (int i = 0; i < NUM_WORK_QUEUE_ITEM_STATS + 1; i++) {
|
|
Packit Service |
b3514a |
totalProcessed += queue->stats.workItemStats.times[i].count;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
return totalProcessed;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
void logWorkQueueStats(const SimpleWorkQueue *queue)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
uint64_t runtimeNS = 0;
|
|
Packit Service |
b3514a |
if (queue->thread != NULL) {
|
|
Packit Service |
b3514a |
runtimeNS += queue->thread->se.sum_exec_runtime;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
unsigned long nsPerWorkItem = 0;
|
|
Packit Service |
b3514a |
uint64_t totalProcessed = getTotalProcessed(queue);
|
|
Packit Service |
b3514a |
if (totalProcessed > 0) {
|
|
Packit Service |
b3514a |
nsPerWorkItem = runtimeNS / totalProcessed;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
unsigned long runtimeMS = runtimeNS / 1000;
|
|
Packit Service |
b3514a |
logInfo("workQ %" PRIptr " (%s) thread cpu usage %lu.%06lus, %" PRIu64
|
|
Packit Service |
b3514a |
" tasks, %lu.%03luus/task",
|
|
Packit Service |
b3514a |
queue,
|
|
Packit Service |
b3514a |
queue->common.name,
|
|
Packit Service |
b3514a |
runtimeMS / 1000000, runtimeMS % 1000000,
|
|
Packit Service |
b3514a |
totalProcessed,
|
|
Packit Service |
b3514a |
nsPerWorkItem / 1000, nsPerWorkItem % 1000);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
ssize_t formatRunTimeStats(const KvdoWorkQueueStats *stats, char *buffer)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
// Get snapshots of all three at approximately the same time.
|
|
Packit Service |
b3514a |
uint64_t startTime = stats->startTime;
|
|
Packit Service |
b3514a |
uint64_t runTime = atomic64_read(&stats->runTime);
|
|
Packit Service |
b3514a |
uint64_t rescheduleTime = atomic64_read(&stats->rescheduleTime);
|
|
Packit Service |
b3514a |
loadFence(); // rdtsc barrier
|
|
Packit Service |
b3514a |
uint64_t now = currentTime(CLOCK_MONOTONIC);
|
|
Packit Service |
b3514a |
uint64_t lifetime = now - startTime;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
return sprintf(buffer,
|
|
Packit Service |
b3514a |
"%llu %llu %llu\n",
|
|
Packit Service |
b3514a |
lifetime, runTime, rescheduleTime);
|
|
Packit Service |
b3514a |
}
|