Skip to content

Commit 44091d2

Browse files
jpirkodavem330
authored andcommitted
lib: Introduce priority array area manager
This introduces a infrastructure for management of linear priority areas. Priority order in an array matters, however order of items inside a priority group does not matter. As an initial implementation, L-sort algorithm is used. It is quite trivial. More advanced algorithm called P-sort will be introduced as a follow-up. The infrastructure is prepared for other algos. Alongside this, a testing module is introduced as well. Signed-off-by: Jiri Pirko <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b862815 commit 44091d2

File tree

7 files changed

+871
-0
lines changed

7 files changed

+871
-0
lines changed

MAINTAINERS

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9382,6 +9382,14 @@ F: drivers/video/fbdev/sti*
93829382
F: drivers/video/console/sti*
93839383
F: drivers/video/logo/logo_parisc*
93849384

9385+
PARMAN
9386+
M: Jiri Pirko <[email protected]>
9387+
9388+
S: Supported
9389+
F: lib/parman.c
9390+
F: lib/test_parman.c
9391+
F: include/linux/parman.h
9392+
93859393
PC87360 HARDWARE MONITORING DRIVER
93869394
M: Jim Cromie <[email protected]>
93879395

include/linux/parman.h

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* include/linux/parman.h - Manager for linear priority array areas
3+
* Copyright (c) 2017 Mellanox Technologies. All rights reserved.
4+
* Copyright (c) 2017 Jiri Pirko <[email protected]>
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions are met:
8+
*
9+
* 1. Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
* 2. Redistributions in binary form must reproduce the above copyright
12+
* notice, this list of conditions and the following disclaimer in the
13+
* documentation and/or other materials provided with the distribution.
14+
* 3. Neither the names of the copyright holders nor the names of its
15+
* contributors may be used to endorse or promote products derived from
16+
* this software without specific prior written permission.
17+
*
18+
* Alternatively, this software may be distributed under the terms of the
19+
* GNU General Public License ("GPL") version 2 as published by the Free
20+
* Software Foundation.
21+
*
22+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32+
* POSSIBILITY OF SUCH DAMAGE.
33+
*/
34+
35+
#ifndef _PARMAN_H
36+
#define _PARMAN_H
37+
38+
#include <linux/list.h>
39+
40+
enum parman_algo_type {
41+
PARMAN_ALGO_TYPE_LSORT,
42+
};
43+
44+
struct parman_item {
45+
struct list_head list;
46+
unsigned long index;
47+
};
48+
49+
struct parman_prio {
50+
struct list_head list;
51+
struct list_head item_list;
52+
unsigned long priority;
53+
};
54+
55+
struct parman_ops {
56+
unsigned long base_count;
57+
unsigned long resize_step;
58+
int (*resize)(void *priv, unsigned long new_count);
59+
void (*move)(void *priv, unsigned long from_index,
60+
unsigned long to_index, unsigned long count);
61+
enum parman_algo_type algo;
62+
};
63+
64+
struct parman;
65+
66+
struct parman *parman_create(const struct parman_ops *ops, void *priv);
67+
void parman_destroy(struct parman *parman);
68+
void parman_prio_init(struct parman *parman, struct parman_prio *prio,
69+
unsigned long priority);
70+
void parman_prio_fini(struct parman_prio *prio);
71+
int parman_item_add(struct parman *parman, struct parman_prio *prio,
72+
struct parman_item *item);
73+
void parman_item_remove(struct parman *parman, struct parman_prio *prio,
74+
struct parman_item *item);
75+
76+
#endif

lib/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,4 +550,7 @@ config STACKDEPOT
550550
config SBITMAP
551551
bool
552552

553+
config PARMAN
554+
tristate "parman"
555+
553556
endmenu

lib/Kconfig.debug

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,6 +1826,16 @@ config TEST_HASH
18261826
This is intended to help people writing architecture-specific
18271827
optimized versions. If unsure, say N.
18281828

1829+
config TEST_PARMAN
1830+
tristate "Perform selftest on priority array manager"
1831+
default n
1832+
depends on PARMAN
1833+
help
1834+
Enable this option to test priority array manager on boot
1835+
(or module load).
1836+
1837+
If unsure, say N.
1838+
18291839
endmenu # runtime tests
18301840

18311841
config PROVIDE_OHCI1394_DMA_INIT

lib/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_key_base.o
5656
obj-$(CONFIG_TEST_PRINTF) += test_printf.o
5757
obj-$(CONFIG_TEST_BITMAP) += test_bitmap.o
5858
obj-$(CONFIG_TEST_UUID) += test_uuid.o
59+
obj-$(CONFIG_TEST_PARMAN) += test_parman.o
5960

6061
ifeq ($(CONFIG_DEBUG_KOBJECT),y)
6162
CFLAGS_kobject.o += -DDEBUG
@@ -230,3 +231,5 @@ obj-$(CONFIG_UBSAN) += ubsan.o
230231
UBSAN_SANITIZE_ubsan.o := n
231232

232233
obj-$(CONFIG_SBITMAP) += sbitmap.o
234+
235+
obj-$(CONFIG_PARMAN) += parman.o

0 commit comments

Comments
 (0)