#include "link.h"
#include "mempool.h"
#include "parser.h"
+#include "swq.h"
#ifndef CMD_MAX_TOKENS
#define CMD_MAX_TOKENS 256
}
}
+/**
+ * swq <swq_name>
+ * size <size>
+ * cpu <cpu_id>
+ */
+static void
+cmd_swq(char **tokens,
+ uint32_t n_tokens,
+ char *out,
+ size_t out_size)
+{
+ struct swq_params p;
+ char *name;
+ struct swq *swq;
+
+ if (n_tokens != 6) {
+ snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+ return;
+ }
+
+ name = tokens[1];
+
+ if (strcmp(tokens[2], "size") != 0) {
+ snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
+ return;
+ }
+
+ if (parser_read_uint32(&p.size, tokens[3]) != 0) {
+ snprintf(out, out_size, MSG_ARG_INVALID, "size");
+ return;
+ }
+
+ if (strcmp(tokens[4], "cpu") != 0) {
+ snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
+ return;
+ }
+
+ if (parser_read_uint32(&p.cpu_id, tokens[5]) != 0) {
+ snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
+ return;
+ }
+
+ swq = swq_create(name, &p);
+ if (swq == NULL) {
+ snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
+ return;
+ }
+}
+
void
cli_process(char *in, char *out, size_t out_size)
{
return;
}
+ if (strcmp(tokens[0], "swq") == 0) {
+ cmd_swq(tokens, n_tokens, out, out_size);
+ return;
+ }
+
snprintf(out, out_size, MSG_CMD_UNKNOWN, tokens[0]);
}
#include "conn.h"
#include "link.h"
#include "mempool.h"
+#include "swq.h"
static const char usage[] =
"%s EAL_ARGS -- [-h HOST] [-p PORT] [-s SCRIPT]\n";
return status;
}
+ /* SWQ */
+ status = swq_init();
+ if (status) {
+ printf("Error: SWQ initialization failed (%d)\n", status);
+ return status;
+ }
+
/* Script */
if (app.script_name)
cli_script_process(app.script_name,
--- /dev/null
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2010-2018 Intel Corporation
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "swq.h"
+
+static struct swq_list swq_list;
+
+int
+swq_init(void)
+{
+ TAILQ_INIT(&swq_list);
+
+ return 0;
+}
+
+struct swq *
+swq_find(const char *name)
+{
+ struct swq *swq;
+
+ if (name == NULL)
+ return NULL;
+
+ TAILQ_FOREACH(swq, &swq_list, node)
+ if (strcmp(swq->name, name) == 0)
+ return swq;
+
+ return NULL;
+}
+
+struct swq *
+swq_create(const char *name, struct swq_params *params)
+{
+ struct swq *swq;
+ struct rte_ring *r;
+ unsigned int flags = RING_F_SP_ENQ | RING_F_SC_DEQ;
+
+ /* Check input params */
+ if ((name == NULL) ||
+ swq_find(name) ||
+ (params == NULL) ||
+ (params->size == 0))
+ return NULL;
+
+ /* Resource create */
+ r = rte_ring_create(
+ name,
+ params->size,
+ params->cpu_id,
+ flags);
+
+ if (r == NULL)
+ return NULL;
+
+ /* Node allocation */
+ swq = calloc(1, sizeof(struct swq));
+ if (swq == NULL) {
+ rte_ring_free(r);
+ return NULL;
+ }
+
+ /* Node fill in */
+ strncpy(swq->name, name, sizeof(swq->name));
+ swq->r = r;
+
+ /* Node add to list */
+ TAILQ_INSERT_TAIL(&swq_list, swq, node);
+
+ return swq;
+}
--- /dev/null
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2010-2018 Intel Corporation
+ */
+
+#ifndef _INCLUDE_SWQ_H_
+#define _INCLUDE_SWQ_H_
+
+#include <stdint.h>
+#include <sys/queue.h>
+
+#include <rte_ring.h>
+
+#include "common.h"
+
+struct swq {
+ TAILQ_ENTRY(swq) node;
+ char name[NAME_SIZE];
+ struct rte_ring *r;
+};
+
+TAILQ_HEAD(swq_list, swq);
+
+int
+swq_init(void);
+
+struct swq *
+swq_find(const char *name);
+
+struct swq_params {
+ uint32_t size;
+ uint32_t cpu_id;
+};
+
+struct swq *
+swq_create(const char *name, struct swq_params *params);
+
+#endif /* _INCLUDE_SWQ_H_ */