|
Packit Service |
310c69 |
/*
|
|
Packit Service |
310c69 |
* Copyright (c) 2020 Red Hat, Inc.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* This program is free software; you can redistribute it and/or
|
|
Packit Service |
310c69 |
* modify it under the terms of the GNU General Public License
|
|
Packit Service |
310c69 |
* as published by the Free Software Foundation; either version 2
|
|
Packit Service |
310c69 |
* of the License, or (at your option) any later version.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* This program is distributed in the hope that it will be useful,
|
|
Packit Service |
310c69 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
310c69 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
310c69 |
* GNU General Public License for more details.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
310c69 |
* along with this program; if not, write to the Free Software
|
|
Packit Service |
310c69 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit Service |
310c69 |
* 02110-1301, USA.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* $Id: //eng/vdo-releases/aluminum/src/c++/vdo/kernel/workQueueSysfs.c#1 $
|
|
Packit Service |
310c69 |
*/
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#include "workQueueSysfs.h"
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#include <linux/kobject.h>
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#include "logger.h"
|
|
Packit Service |
310c69 |
#include "memoryAlloc.h"
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#include "workQueueInternals.h"
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
typedef struct workQueueAttribute {
|
|
Packit Service |
310c69 |
struct attribute attr;
|
|
Packit Service |
310c69 |
ssize_t (*show)(const KvdoWorkQueue *queue, char *buf);
|
|
Packit Service |
310c69 |
ssize_t (*store)(KvdoWorkQueue *queue, const char *buf, size_t length);
|
|
Packit Service |
310c69 |
} WorkQueueAttribute;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**********************************************************************/
|
|
Packit Service |
310c69 |
static ssize_t nameShow(const KvdoWorkQueue *queue, char *buf)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
return sprintf(buf, "%s\n", queue->name);
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**********************************************************************/
|
|
Packit Service |
310c69 |
static ssize_t pidShow(const KvdoWorkQueue *queue, char *buf)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
return sprintf(buf, "%ld\n",
|
|
Packit Service |
310c69 |
(long) atomic_read(&asConstSimpleWorkQueue(queue)->threadID));
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**********************************************************************/
|
|
Packit Service |
310c69 |
static ssize_t timesShow(const KvdoWorkQueue *queue, char *buf)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
return formatRunTimeStats(&asConstSimpleWorkQueue(queue)->stats, buf);
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**********************************************************************/
|
|
Packit Service |
310c69 |
static ssize_t typeShow(const KvdoWorkQueue *queue, char *buf)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
strcpy(buf, queue->roundRobinMode ? "round-robin\n" : "simple\n");
|
|
Packit Service |
310c69 |
return strlen(buf);
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**********************************************************************/
|
|
Packit Service |
310c69 |
static ssize_t workFunctionsShow(const KvdoWorkQueue *queue, char *buf)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
const SimpleWorkQueue *simpleQueue = asConstSimpleWorkQueue(queue);
|
|
Packit Service |
310c69 |
return formatWorkItemStats(&simpleQueue->stats.workItemStats, buf,
|
|
Packit Service |
310c69 |
PAGE_SIZE);
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**********************************************************************/
|
|
Packit Service |
310c69 |
static WorkQueueAttribute nameAttr = {
|
|
Packit Service |
310c69 |
.attr = { .name = "name", .mode = 0444, },
|
|
Packit Service |
310c69 |
.show = nameShow,
|
|
Packit Service |
310c69 |
};
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**********************************************************************/
|
|
Packit Service |
310c69 |
static WorkQueueAttribute pidAttr = {
|
|
Packit Service |
310c69 |
.attr = { .name = "pid", .mode = 0444, },
|
|
Packit Service |
310c69 |
.show = pidShow,
|
|
Packit Service |
310c69 |
};
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**********************************************************************/
|
|
Packit Service |
310c69 |
static WorkQueueAttribute timesAttr = {
|
|
Packit Service |
310c69 |
.attr = { .name = "times", .mode = 0444 },
|
|
Packit Service |
310c69 |
.show = timesShow,
|
|
Packit Service |
310c69 |
};
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**********************************************************************/
|
|
Packit Service |
310c69 |
static WorkQueueAttribute typeAttr = {
|
|
Packit Service |
310c69 |
.attr = { .name = "type", .mode = 0444, },
|
|
Packit Service |
310c69 |
.show = typeShow,
|
|
Packit Service |
310c69 |
};
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**********************************************************************/
|
|
Packit Service |
310c69 |
static WorkQueueAttribute workFunctionsAttr = {
|
|
Packit Service |
310c69 |
.attr = { .name = "work_functions", .mode = 0444, },
|
|
Packit Service |
310c69 |
.show = workFunctionsShow,
|
|
Packit Service |
310c69 |
};
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**********************************************************************/
|
|
Packit Service |
310c69 |
static struct attribute *simpleWorkQueueAttrs[] = {
|
|
Packit Service |
310c69 |
&nameAttr.attr,
|
|
Packit Service |
310c69 |
&pidAttr.attr,
|
|
Packit Service |
310c69 |
×Attr.attr,
|
|
Packit Service |
310c69 |
&typeAttr.attr,
|
|
Packit Service |
310c69 |
&workFunctionsAttr.attr,
|
|
Packit Service |
310c69 |
NULL,
|
|
Packit Service |
310c69 |
};
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**********************************************************************/
|
|
Packit Service |
310c69 |
static struct attribute *roundRobinWorkQueueAttrs[] = {
|
|
Packit Service |
310c69 |
&nameAttr.attr,
|
|
Packit Service |
310c69 |
&typeAttr.attr,
|
|
Packit Service |
310c69 |
NULL,
|
|
Packit Service |
310c69 |
};
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**********************************************************************/
|
|
Packit Service |
310c69 |
static ssize_t workQueueAttrShow(struct kobject *kobj,
|
|
Packit Service |
310c69 |
struct attribute *attr,
|
|
Packit Service |
310c69 |
char *buf)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
WorkQueueAttribute *wqAttr = container_of(attr, WorkQueueAttribute, attr);
|
|
Packit Service |
310c69 |
if (wqAttr->show == NULL) {
|
|
Packit Service |
310c69 |
return -EINVAL;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
KvdoWorkQueue *queue = container_of(kobj, KvdoWorkQueue, kobj);
|
|
Packit Service |
310c69 |
return wqAttr->show(queue, buf);
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**********************************************************************/
|
|
Packit Service |
310c69 |
static ssize_t workQueueAttrStore(struct kobject *kobj,
|
|
Packit Service |
310c69 |
struct attribute *attr,
|
|
Packit Service |
310c69 |
const char *buf,
|
|
Packit Service |
310c69 |
size_t length)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
WorkQueueAttribute *wqAttr = container_of(attr, WorkQueueAttribute, attr);
|
|
Packit Service |
310c69 |
if (wqAttr->store == NULL) {
|
|
Packit Service |
310c69 |
return -EINVAL;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
KvdoWorkQueue *queue = container_of(kobj, KvdoWorkQueue, kobj);
|
|
Packit Service |
310c69 |
return wqAttr->store(queue, buf, length);
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**********************************************************************/
|
|
Packit Service |
310c69 |
static struct sysfs_ops workQueueSysfsOps = {
|
|
Packit Service |
310c69 |
.show = workQueueAttrShow,
|
|
Packit Service |
310c69 |
.store = workQueueAttrStore,
|
|
Packit Service |
310c69 |
};
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**********************************************************************/
|
|
Packit Service |
310c69 |
static void workQueueRelease(struct kobject *kobj)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
KvdoWorkQueue *queue = container_of(kobj, KvdoWorkQueue, kobj);
|
|
Packit Service |
310c69 |
FREE(queue->name);
|
|
Packit Service |
310c69 |
if (queue->roundRobinMode) {
|
|
Packit Service |
310c69 |
FREE(asRoundRobinWorkQueue(queue));
|
|
Packit Service |
310c69 |
} else {
|
|
Packit Service |
310c69 |
FREE(asSimpleWorkQueue(queue));
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**********************************************************************/
|
|
Packit Service |
310c69 |
struct kobj_type simpleWorkQueueKobjType = {
|
|
Packit Service |
310c69 |
.default_attrs = simpleWorkQueueAttrs,
|
|
Packit Service |
310c69 |
.release = workQueueRelease,
|
|
Packit Service |
310c69 |
.sysfs_ops = &workQueueSysfsOps,
|
|
Packit Service |
310c69 |
};
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**********************************************************************/
|
|
Packit Service |
310c69 |
struct kobj_type roundRobinWorkQueueKobjType = {
|
|
Packit Service |
310c69 |
.default_attrs = roundRobinWorkQueueAttrs,
|
|
Packit Service |
310c69 |
.release = workQueueRelease,
|
|
Packit Service |
310c69 |
.sysfs_ops = &workQueueSysfsOps,
|
|
Packit Service |
310c69 |
};
|