From patchwork Thu Apr 6 11:59:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petri Savolainen X-Patchwork-Id: 96934 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp695443qgd; Thu, 6 Apr 2017 05:01:56 -0700 (PDT) X-Received: by 10.200.41.42 with SMTP id y39mr33728504qty.37.1491480116147; Thu, 06 Apr 2017 05:01:56 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id p53si1190801qtp.306.2017.04.06.05.01.55; Thu, 06 Apr 2017 05:01:56 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id BFF5F62C41; Thu, 6 Apr 2017 12:01:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAD_ENC_HEADER,BAYES_00, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 4067C64368; Thu, 6 Apr 2017 12:00:00 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id E0A0960762; Thu, 6 Apr 2017 11:59:48 +0000 (UTC) Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on0112.outbound.protection.outlook.com [104.47.0.112]) by lists.linaro.org (Postfix) with ESMTPS id 69A0960734 for ; Thu, 6 Apr 2017 11:59:45 +0000 (UTC) Received: from DB4PR07CA042.eurprd07.prod.outlook.com (2a01:111:e400:9828::52) by AM3PR07MB1060.eurprd07.prod.outlook.com (2a01:111:e400:536e::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1019.8; Thu, 6 Apr 2017 11:59:43 +0000 Received: from DB5EUR03FT051.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e0a::201) by DB4PR07CA042.outlook.office365.com (2a01:111:e400:9828::52) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1019.8 via Frontend Transport; Thu, 6 Apr 2017 11:59:43 +0000 Received-SPF: SoftFail (protection.outlook.com: domain of transitioning linaro.org discourages use of 131.228.2.241 as permitted sender) Received: from mailrelay.int.nokia.com (131.228.2.241) by DB5EUR03FT051.mail.protection.outlook.com (10.152.21.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.1005.5 via Frontend Transport; Thu, 6 Apr 2017 11:59:43 +0000 Received: from fihe3nok0735.emea.nsn-net.net (localhost [127.0.0.1]) by fihe3nok0735.emea.nsn-net.net (8.14.9/8.14.5) with ESMTP id v36Bx5t4006041 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 6 Apr 2017 14:59:05 +0300 Received: from 10.144.19.15 ([10.144.104.219]) by fihe3nok0735.emea.nsn-net.net (8.14.9/8.14.5) with ESMTP id v36Bx4nM006023 (version=TLSv1/SSLv3 cipher=AES128-SHA256 bits=128 verify=NOT) for ; Thu, 6 Apr 2017 14:59:05 +0300 X-HPESVCS-Source-Ip: 10.144.104.219 From: Petri Savolainen To: Date: Thu, 6 Apr 2017 14:59:04 +0300 Message-ID: <1491479944-31232-3-git-send-email-petri.savolainen@linaro.org> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1491479944-31232-1-git-send-email-petri.savolainen@linaro.org> References: <1491479944-31232-1-git-send-email-petri.savolainen@linaro.org> X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:131.228.2.241; IPV:CAL; CTRY:FI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(39840400002)(39450400003)(39400400002)(39850400002)(39860400002)(39410400002)(2980300002)(199003)(189002)(9170700003)(305945005)(356003)(47776003)(50986999)(76176999)(5660300001)(22756006)(36756003)(86362001)(48376002)(77096006)(2950100002)(33646002)(6916009)(38730400002)(53936002)(110136004)(189998001)(50226002)(2906002)(5003940100001)(106466001)(81166006)(8936002)(2351001)(105596002)(8676002); DIR:OUT; SFP:1102; SCL:1; SRVR:AM3PR07MB1060; H:mailrelay.int.nokia.com; FPR:; SPF:SoftFail; MLV:sfv; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; DB5EUR03FT051; 1:5mF8FyNY9eZf6mOvKu4ULvXg+NLHQ7Kgyh7fypggsY3dGYYxUihmToTaR8Dpd9PQuESXD2jFVsYMfzq15d6bakz32EDEKj2YbjgG5i4NIcM2JWe11Wv/+70imlcYdwyDo4pu4axZ+n9rV2SAIrxEuy1bS53wxR9PLTS++t9S3x8z9lcIGWgnB9Kdbmmpq4pBouG10E0x+dFWwCyotY9mNstLUQvxCfanNC+E+Rp3kX3VlY/3LVdYsGiNgyx1kIsgA33RBakrbk3rLowgL0I7HPXaMsK27sn1N/zEa6uw3e4JM4fQTOo8dULqVfJMhZQ/6x6U+SSVE/pn3x7iTzBVT0dJMADGPX3US9O37U/Q5TowUVQDmKPhr1KOb7FkXPgn17ppmzErCz/60EyINCKGp5kxNfLAi2X4Sj5aksHXV6XuECLmOPQ5ve4WIhgMGcNRgH116bLF2oynwkKloDXUU7RYFZ7XKZoYQmFUEv+0xQ9+JNMK5g8WDoGclIBpFuHnqnZYVc7qMhxrVuUgsYGing== MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: b7afedd2-0f0b-440a-2b7e-08d47ce469ac X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(2017030254075)(201703131423075)(201703031133081); SRVR:AM3PR07MB1060; X-Microsoft-Exchange-Diagnostics: 1; AM3PR07MB1060; 3:jq0sa5TeES6wlYmjmZGhx2xfWopoIFmk0zNH8mmr5XeqUO6BuX92RkSkREZweNZqYsnhWEP6cLsFyjC8sh3Ku8C4LvO2s+z06PNN9KnY7AAVHIns8cOngsJG3IecbEaU0EqWvkIPqcGDn7RmqoYeSpy/aX8K+EavmCNUhdrm0+wcfvV20S9r1eaHeYQnvV9Yd05ua69ue/6+niSqB1713pabD2AaKaDNLKjxTkuEw2TZXI1MT7no17pV+7zx0mdC/3yah3IZRzA9ONEdh8XHfkRk/bHqnTfmOhIsTEczCTRJJ8Sw94ZI0wdrVQQuCokyqxk0x2u1AFOnx1DjOksSb5omhXhGBATZ0ml4ddZru0HjFSeIeANPmxa0VbysS6nBawqb7+sPa2SjlTz5pLmwr6dbgLHcKH51s6M4IlKyJRdPgd+m+bndIIoCIyv6aj3N2UF4rYWJilzeaOBE/JvpmA==; 25:8OyOelox1MwO0nd6GP4U2rFHQ+RVvDwntt+S3mGzodI9/OYXKoBykUB2zeYdOOVO78dbq/J5nhgIM/+gD0jXOJ4plvbXPxm4aLFqCosNVR9GaSA3WABwV5IKx0213mctO52Ry6bbySkBJWu9/4ASV0I7UEFz+xvlZlxg3vJEkTFQ6XxXlNlZeVqnz1cIPjwscV10QiOTr/q+CHOauqEji36zETDUjYTYiz2CiaNbuSyXnd1M2tVdsDXRWYThE1+8IfNnrc0oraqdH0WVFTLZImoCzkD025EJV8YDMANXWZU5c9U+HMSiN2CSRxu9AAQ78UxWZW0M2CpqQt6KgnVtM0L5+9fw0i7aD6TdMNqst5O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S: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(601004)(2401047)(8121501046)(5005006)(13023025)(13021025)(13013025)(93006095)(93003095)(10201501046)(3002001)(6055026)(6041248)(20161123555025)(20161123560025)(20161123564025)(20161123562025)(201703131423075)(201702281528075)(201703061421075)(6072148); SRVR:AM3PR07MB1060; BCL:0; PCL:0; RULEID:; SRVR:AM3PR07MB1060; X-Microsoft-Exchange-Diagnostics: 1; AM3PR07MB1060; 4:4F8DwAUJUSU4VOL0345CXg8E9lZ2jCl8591spq915wCyz5RoDjmEAodL0hx1Jh7rT1J8q7vrSEpQi75aKiH/7r1+xblNUpvA/52PBGWjBxUjcX1+tf72wo1rXuBsTOvQpbX04elGZtDAXp7Mk4633exAQrWB51hfyD6wZYCjRrn8bo5PvlFHQfiAwCkEiRimQRoOVzHk0RFGkOuDb9zvSLeUoWgVp548/e1Kyn+B77U28iDUbu0qoRBo/+wXwBYk+TAJ0PhxA7xAmIOf1TkoWyMA2I+ERb/Owabz+hIYVAln2l4+xa9sdc8leXvttFBjKcmRjjclfHH+C1S3DAIwcY/kcfBU7++V3MC/0aPgOIPHgrosRc03Qp0n5B9CXFnKmu1GNuOergDar0m3tIeipdMPccxqTMt/zoeL8pqhZPu7wxz+debfQBerAu1YCqeQJFTfV8vzuN9maGJtg8ZyDq6kqTeSIi5sdriDxiZRCNdnQx4/t4kcXdz7JxCVPetjYCpKwY7Jb+NuRrQ7vORb8k4YVVvdm166ii0UbIWHovM+X3v4vSIE9P7D2IE9oSHWhPZ8BWbbZ67F7EcO9cqd59vd2uVRnTzn4/rIFqcTl3CDXu2xFL2kDH0DnEUg0y4Kn41vqbfTvvPeYI58vtZ76vxqnis3mIipm/jseslJboPCruSV0FN4ZhgMtc2B6GuAiZg+KRR8boy4g5eGL/Wx+N2Xygh25JAfU+VZsio7IFbeP3Js05ft9KmKwgcNQwOFK7hxpjhfmJoNYri5c9GbIduTdkN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Ci060s1+9RXBxf8= X-Microsoft-Exchange-Diagnostics: 1; AM3PR07MB1060; 6:jxEq9mmzsCi/bYpTNVTJS5RrD8uSLLUzi4MObmePY9TvkpfRNBAz7bpymOBKTbA48fJ2Lez/vxfoXP3P7hZIYl2EWydpTbnvBakxqwSiK/9YVkqKCu71mSzeABFF6qoA2c8PWb4gTWRN5gJ7+s6sp2jZ9xt8FycEzu5O8/QC04sTYrTVherfrefgrUW7fzpKbyFEvIDKQR+0QDAziGnhCCf2cTLB+w3Gwi+Bw0H/JCWSjNmtI2VI+4rPmLs9Ml8SWB1sVXQxk1Tg/NHcFXm4HeWYeSsVrw+TvK3I2TIsqhRCM+nwTUUuISSpDnN5nrqeZBegYcQH+QdhAV/3YwaeUqgYFsJdiC8CGO9dDDXk+ehgVf76dYrYJQwKDUjf2Oe1p5mDalETlX6FspqEQ23Iu+LFz8g5zuCzU1SFU6J86txRMR+ys34Q3VWiPyimE6372Q65pG/CK6lMe/cAwfWf4fUmlzRHIsn07Eb3ul07OfQ=; 5:YswTb0fG5/zbYGflMCw3jsnzCpJwk2q4/haVk6r0H38SERrE6DgrKFl8CqyS37k3tR4Jw/vpHmnlST0hAIavzWD22csa8wdCtV2Go4po2AD0dGrqx40+j+9myntnP7kvTHmBzOWgKowpasbSPhlapw==; 24:ZmiNBigtJ9kSSXcGsLLeN5N4mgU3+sR/oLGf7D8XyPlFKCr/mRGpOi1/OCSCAI+4gK0iTN+0BE0pju8Iqh715f4COqYqYxtw73BMG8O016Y= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM3PR07MB1060; 7:8ODFs0S+Rw3jBodk76YACzPgRAAx2K/CYsxN04hMrgfudzAKBbsyiUhyj34xoK4vZOfPpY8BaAbAjbZTgsTQOJJZWenHwkJd6tP0lUuYjQ1mY9s14Paep1Ja8OtVhcQ4sXvI8bV7FhrVRLXAVDoGIj2lrEpWaLbYl2nQDlluQ90P1FlTdEs+SssEgrPgtj3p7ycGKSA9zzEmb1VwTzWiGpM4V5RBx21twGqumlbJs2hrSgLEsb5Gx86GvnN3X9ew4B2M83HnorJdFOeqT25rFZ5ZCWgRHJeOLrSs0mpKXNdMoGcSjoXGYN4P/dAwqmZsem9odaHLSDR+Z+JwaW1CRw== X-OriginatorOrg: nokia.onmicrosoft.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Apr 2017 11:59:43.1329 (UTC) X-MS-Exchange-CrossTenant-Id: 5d471751-9675-428d-917b-70f44f9630b0 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5d471751-9675-428d-917b-70f44f9630b0; Ip=[131.228.2.241]; Helo=[mailrelay.int.nokia.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM3PR07MB1060 Subject: [lng-odp] [PATCH 3/3] linux-gen: sched: optimize group scheduling X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Use separate priority queues for different groups. Sharing the same priority queue over multiple groups caused multiple issues: * latency and ordering issues when threads push back events (from wrong groups) to the tail of the priority queue * unnecessary contention (scaling issues) when threads belong to different groups Lowered the maximum number of groups from 256 to 32 (in the default configuration) to limit memory usage of priority queues. This should be enough for the most users. Signed-off-by: Petri Savolainen --- platform/linux-generic/odp_schedule.c | 284 +++++++++++++++++++++++----------- 1 file changed, 195 insertions(+), 89 deletions(-) -- 2.8.1 diff --git a/platform/linux-generic/odp_schedule.c b/platform/linux-generic/odp_schedule.c index e7079b9..f366e7e 100644 --- a/platform/linux-generic/odp_schedule.c +++ b/platform/linux-generic/odp_schedule.c @@ -34,7 +34,7 @@ ODP_STATIC_ASSERT((ODP_SCHED_PRIO_NORMAL > 0) && "normal_prio_is_not_between_highest_and_lowest"); /* Number of scheduling groups */ -#define NUM_SCHED_GRPS 256 +#define NUM_SCHED_GRPS 32 /* Priority queues per priority */ #define QUEUES_PER_PRIO 4 @@ -163,7 +163,11 @@ typedef struct { ordered_stash_t stash[MAX_ORDERED_STASH]; } ordered; + uint32_t grp_epoch; + int num_grp; + uint8_t grp[NUM_SCHED_GRPS]; uint8_t weight_tbl[WEIGHT_TBL_SIZE]; + uint8_t grp_weight[WEIGHT_TBL_SIZE]; } sched_local_t; @@ -199,7 +203,7 @@ typedef struct { pri_mask_t pri_mask[NUM_PRIO]; odp_spinlock_t mask_lock; - prio_queue_t prio_q[NUM_PRIO][QUEUES_PER_PRIO]; + prio_queue_t prio_q[NUM_SCHED_GRPS][NUM_PRIO][QUEUES_PER_PRIO]; odp_spinlock_t poll_cmd_lock; /* Number of commands in a command queue */ @@ -214,8 +218,10 @@ typedef struct { odp_shm_t shm; uint32_t pri_count[NUM_PRIO][QUEUES_PER_PRIO]; - odp_spinlock_t grp_lock; - odp_thrmask_t mask_all; + odp_thrmask_t mask_all; + odp_spinlock_t grp_lock; + odp_atomic_u32_t grp_epoch; + struct { char name[ODP_SCHED_GROUP_NAME_LEN]; odp_thrmask_t mask; @@ -223,6 +229,7 @@ typedef struct { } sched_grp[NUM_SCHED_GRPS]; struct { + int grp; int prio; int queue_per_prio; } queue[ODP_CONFIG_QUEUES]; @@ -273,7 +280,7 @@ static void sched_local_init(void) static int schedule_init_global(void) { odp_shm_t shm; - int i, j; + int i, j, grp; ODP_DBG("Schedule init ... "); @@ -293,15 +300,20 @@ static int schedule_init_global(void) sched->shm = shm; odp_spinlock_init(&sched->mask_lock); - for (i = 0; i < NUM_PRIO; i++) { - for (j = 0; j < QUEUES_PER_PRIO; j++) { - int k; + for (grp = 0; grp < NUM_SCHED_GRPS; grp++) { + for (i = 0; i < NUM_PRIO; i++) { + for (j = 0; j < QUEUES_PER_PRIO; j++) { + prio_queue_t *prio_q; + int k; - ring_init(&sched->prio_q[i][j].ring); + prio_q = &sched->prio_q[grp][i][j]; + ring_init(&prio_q->ring); - for (k = 0; k < PRIO_QUEUE_RING_SIZE; k++) - sched->prio_q[i][j].queue_index[k] = - PRIO_QUEUE_EMPTY; + for (k = 0; k < PRIO_QUEUE_RING_SIZE; k++) { + prio_q->queue_index[k] = + PRIO_QUEUE_EMPTY; + } + } } } @@ -317,12 +329,17 @@ static int schedule_init_global(void) sched->pktio_cmd[i].cmd_index = PKTIO_CMD_FREE; odp_spinlock_init(&sched->grp_lock); + odp_atomic_init_u32(&sched->grp_epoch, 0); for (i = 0; i < NUM_SCHED_GRPS; i++) { memset(sched->sched_grp[i].name, 0, ODP_SCHED_GROUP_NAME_LEN); odp_thrmask_zero(&sched->sched_grp[i].mask); } + sched->sched_grp[ODP_SCHED_GROUP_ALL].allocated = 1; + sched->sched_grp[ODP_SCHED_GROUP_WORKER].allocated = 1; + sched->sched_grp[ODP_SCHED_GROUP_CONTROL].allocated = 1; + odp_thrmask_setall(&sched->mask_all); ODP_DBG("done\n"); @@ -330,29 +347,38 @@ static int schedule_init_global(void) return 0; } +static inline void queue_destroy_finalize(uint32_t qi) +{ + sched_cb_queue_destroy_finalize(qi); +} + static int schedule_term_global(void) { int ret = 0; int rc = 0; - int i, j; + int i, j, grp; - for (i = 0; i < NUM_PRIO; i++) { - for (j = 0; j < QUEUES_PER_PRIO; j++) { - ring_t *ring = &sched->prio_q[i][j].ring; - uint32_t qi; + for (grp = 0; grp < NUM_SCHED_GRPS; grp++) { + for (i = 0; i < NUM_PRIO; i++) { + for (j = 0; j < QUEUES_PER_PRIO; j++) { + ring_t *ring = &sched->prio_q[grp][i][j].ring; + uint32_t qi; - while ((qi = ring_deq(ring, PRIO_QUEUE_MASK)) != - RING_EMPTY) { - odp_event_t events[1]; - int num; + while ((qi = ring_deq(ring, PRIO_QUEUE_MASK)) != + RING_EMPTY) { + odp_event_t events[1]; + int num; - num = sched_cb_queue_deq_multi(qi, events, 1); + num = sched_cb_queue_deq_multi(qi, + events, + 1); - if (num < 0) - sched_cb_queue_destroy_finalize(qi); + if (num < 0) + queue_destroy_finalize(qi); - if (num > 0) - ODP_ERR("Queue not empty\n"); + if (num > 0) + ODP_ERR("Queue not empty\n"); + } } } } @@ -383,6 +409,40 @@ static int schedule_term_local(void) return 0; } +static inline void grp_update_mask(int grp, const odp_thrmask_t *new_mask) +{ + odp_thrmask_copy(&sched->sched_grp[grp].mask, new_mask); + odp_atomic_add_rel_u32(&sched->grp_epoch, 1); +} + +static inline int grp_update_tbl(void) +{ + int i; + int num = 0; + int thr = sched_local.thr; + + odp_spinlock_lock(&sched->grp_lock); + + for (i = 0; i < NUM_SCHED_GRPS; i++) { + if (sched->sched_grp[i].allocated == 0) + continue; + + if (odp_thrmask_isset(&sched->sched_grp[i].mask, thr)) { + sched_local.grp[num] = i; + num++; + } + } + + odp_spinlock_unlock(&sched->grp_lock); + + /* Update group weights. Round robin over all thread's groups. */ + for (i = 0; i < WEIGHT_TBL_SIZE; i++) + sched_local.grp_weight[i] = i % num; + + sched_local.num_grp = num; + return num; +} + static unsigned schedule_max_ordered_locks(void) { return MAX_ORDERED_LOCKS_PER_QUEUE; @@ -433,6 +493,7 @@ static int schedule_init_queue(uint32_t queue_index, int prio = sched_param->prio; pri_set_queue(queue_index, prio); + sched->queue[queue_index].grp = sched_param->group; sched->queue[queue_index].prio = prio; sched->queue[queue_index].queue_per_prio = queue_per_prio(queue_index); @@ -444,6 +505,7 @@ static void schedule_destroy_queue(uint32_t queue_index) int prio = sched->queue[queue_index].prio; pri_clr_queue(queue_index, prio); + sched->queue[queue_index].grp = 0; sched->queue[queue_index].prio = 0; sched->queue[queue_index].queue_per_prio = 0; } @@ -535,9 +597,10 @@ static void schedule_release_atomic(void) uint32_t qi = sched_local.queue_index; if (qi != PRIO_QUEUE_EMPTY && sched_local.num == 0) { - int prio = sched->queue[qi].prio; + int grp = sched->queue[qi].grp; + int prio = sched->queue[qi].prio; int queue_per_prio = sched->queue[qi].queue_per_prio; - ring_t *ring = &sched->prio_q[prio][queue_per_prio].ring; + ring_t *ring = &sched->prio_q[grp][prio][queue_per_prio].ring; /* Release current atomic queue */ ring_enq(ring, PRIO_QUEUE_MASK, qi); @@ -688,42 +751,14 @@ static int schedule_ord_enq_multi(uint32_t queue_index, void *buf_hdr[], return 1; } -/* - * Schedule queues - */ -static int do_schedule(odp_queue_t *out_queue, odp_event_t out_ev[], - unsigned int max_num) +static inline int do_schedule_grp(odp_queue_t *out_queue, odp_event_t out_ev[], + unsigned int max_num, int grp, int first) { int prio, i; int ret; - int id, first; + int id; unsigned int max_deq = MAX_DEQ; uint32_t qi; - uint16_t round; - - if (sched_local.num) { - ret = copy_events(out_ev, max_num); - - if (out_queue) - *out_queue = sched_local.queue; - - return ret; - } - - schedule_release_context(); - - if (odp_unlikely(sched_local.pause)) - return 0; - - /* Each thread prefers a priority queue. Poll weight table avoids - * starvation of other priority queues on low thread counts. */ - round = sched_local.round + 1; - - if (odp_unlikely(round == WEIGHT_TBL_SIZE)) - round = 0; - - sched_local.round = round; - first = sched_local.weight_tbl[round]; /* Schedule events */ for (prio = 0; prio < NUM_PRIO; prio++) { @@ -736,7 +771,6 @@ static int do_schedule(odp_queue_t *out_queue, odp_event_t out_ev[], for (i = 0; i < QUEUES_PER_PRIO;) { int num; - int grp; int ordered; odp_queue_t handle; ring_t *ring; @@ -753,7 +787,7 @@ static int do_schedule(odp_queue_t *out_queue, odp_event_t out_ev[], } /* Get queue index from the priority queue */ - ring = &sched->prio_q[prio][id].ring; + ring = &sched->prio_q[grp][prio][id].ring; qi = ring_deq(ring, PRIO_QUEUE_MASK); /* Priority queue empty */ @@ -763,21 +797,6 @@ static int do_schedule(odp_queue_t *out_queue, odp_event_t out_ev[], continue; } - grp = sched_cb_queue_grp(qi); - - if (grp > ODP_SCHED_GROUP_ALL && - !odp_thrmask_isset(&sched->sched_grp[grp].mask, - sched_local.thr)) { - /* This thread is not eligible for work from - * this queue, so continue scheduling it. - */ - ring_enq(ring, PRIO_QUEUE_MASK, qi); - - i++; - id++; - continue; - } - /* Low priorities have smaller batch size to limit * head of line blocking latency. */ if (odp_unlikely(prio > ODP_SCHED_PRIO_DEFAULT)) @@ -845,6 +864,70 @@ static int do_schedule(odp_queue_t *out_queue, odp_event_t out_ev[], } } + return 0; +} + +/* + * Schedule queues + */ +static inline int do_schedule(odp_queue_t *out_queue, odp_event_t out_ev[], + unsigned int max_num) +{ + int i, num_grp; + int ret; + int id, first, grp_id; + uint16_t round; + uint32_t epoch; + + if (sched_local.num) { + ret = copy_events(out_ev, max_num); + + if (out_queue) + *out_queue = sched_local.queue; + + return ret; + } + + schedule_release_context(); + + if (odp_unlikely(sched_local.pause)) + return 0; + + /* Each thread prefers a priority queue. Poll weight table avoids + * starvation of other priority queues on low thread counts. */ + round = sched_local.round + 1; + + if (odp_unlikely(round == WEIGHT_TBL_SIZE)) + round = 0; + + sched_local.round = round; + first = sched_local.weight_tbl[round]; + + epoch = odp_atomic_load_acq_u32(&sched->grp_epoch); + num_grp = sched_local.num_grp; + + if (odp_unlikely(sched_local.grp_epoch != epoch)) { + num_grp = grp_update_tbl(); + sched_local.grp_epoch = epoch; + } + + grp_id = sched_local.grp_weight[round]; + + /* Schedule queues per group and priority */ + for (i = 0; i < num_grp; i++) { + int grp; + + grp = sched_local.grp[grp_id]; + ret = do_schedule_grp(out_queue, out_ev, max_num, grp, first); + + if (odp_likely(ret)) + return ret; + + grp_id++; + if (odp_unlikely(grp_id >= num_grp)) + grp_id = 0; + } + /* * Poll packet input when there are no events * * Each thread starts the search for a poll command from its @@ -1050,7 +1133,8 @@ static odp_schedule_group_t schedule_group_create(const char *name, ODP_SCHED_GROUP_NAME_LEN - 1); grp_name[ODP_SCHED_GROUP_NAME_LEN - 1] = 0; } - odp_thrmask_copy(&sched->sched_grp[i].mask, mask); + + grp_update_mask(i, mask); group = (odp_schedule_group_t)i; sched->sched_grp[i].allocated = 1; break; @@ -1063,13 +1147,16 @@ static odp_schedule_group_t schedule_group_create(const char *name, static int schedule_group_destroy(odp_schedule_group_t group) { + odp_thrmask_t zero; int ret; + odp_thrmask_zero(&zero); + odp_spinlock_lock(&sched->grp_lock); if (group < NUM_SCHED_GRPS && group >= SCHED_GROUP_NAMED && sched->sched_grp[group].allocated) { - odp_thrmask_zero(&sched->sched_grp[group].mask); + grp_update_mask(group, &zero); memset(sched->sched_grp[group].name, 0, ODP_SCHED_GROUP_NAME_LEN); sched->sched_grp[group].allocated = 0; @@ -1109,9 +1196,11 @@ static int schedule_group_join(odp_schedule_group_t group, if (group < NUM_SCHED_GRPS && group >= SCHED_GROUP_NAMED && sched->sched_grp[group].allocated) { - odp_thrmask_or(&sched->sched_grp[group].mask, - &sched->sched_grp[group].mask, - mask); + odp_thrmask_t new_mask; + + odp_thrmask_or(&new_mask, &sched->sched_grp[group].mask, mask); + grp_update_mask(group, &new_mask); + ret = 0; } else { ret = -1; @@ -1124,18 +1213,19 @@ static int schedule_group_join(odp_schedule_group_t group, static int schedule_group_leave(odp_schedule_group_t group, const odp_thrmask_t *mask) { + odp_thrmask_t new_mask; int ret; + odp_thrmask_xor(&new_mask, mask, &sched->mask_all); + odp_spinlock_lock(&sched->grp_lock); if (group < NUM_SCHED_GRPS && group >= SCHED_GROUP_NAMED && sched->sched_grp[group].allocated) { - odp_thrmask_t leavemask; + odp_thrmask_and(&new_mask, &sched->sched_grp[group].mask, + &new_mask); + grp_update_mask(group, &new_mask); - odp_thrmask_xor(&leavemask, mask, &sched->mask_all); - odp_thrmask_and(&sched->sched_grp[group].mask, - &sched->sched_grp[group].mask, - &leavemask); ret = 0; } else { ret = -1; @@ -1186,12 +1276,19 @@ static int schedule_group_info(odp_schedule_group_t group, static int schedule_thr_add(odp_schedule_group_t group, int thr) { + odp_thrmask_t mask; + odp_thrmask_t new_mask; + if (group < 0 || group >= SCHED_GROUP_NAMED) return -1; + odp_thrmask_zero(&mask); + odp_thrmask_set(&mask, thr); + odp_spinlock_lock(&sched->grp_lock); - odp_thrmask_set(&sched->sched_grp[group].mask, thr); + odp_thrmask_or(&new_mask, &sched->sched_grp[group].mask, &mask); + grp_update_mask(group, &new_mask); odp_spinlock_unlock(&sched->grp_lock); @@ -1200,12 +1297,20 @@ static int schedule_thr_add(odp_schedule_group_t group, int thr) static int schedule_thr_rem(odp_schedule_group_t group, int thr) { + odp_thrmask_t mask; + odp_thrmask_t new_mask; + if (group < 0 || group >= SCHED_GROUP_NAMED) return -1; + odp_thrmask_zero(&mask); + odp_thrmask_set(&mask, thr); + odp_thrmask_xor(&new_mask, &mask, &sched->mask_all); + odp_spinlock_lock(&sched->grp_lock); - odp_thrmask_clr(&sched->sched_grp[group].mask, thr); + odp_thrmask_and(&new_mask, &sched->sched_grp[group].mask, &new_mask); + grp_update_mask(group, &new_mask); odp_spinlock_unlock(&sched->grp_lock); @@ -1219,9 +1324,10 @@ static void schedule_prefetch(int num ODP_UNUSED) static int schedule_sched_queue(uint32_t queue_index) { + int grp = sched->queue[queue_index].grp; int prio = sched->queue[queue_index].prio; int queue_per_prio = sched->queue[queue_index].queue_per_prio; - ring_t *ring = &sched->prio_q[prio][queue_per_prio].ring; + ring_t *ring = &sched->prio_q[grp][prio][queue_per_prio].ring; ring_enq(ring, PRIO_QUEUE_MASK, queue_index); return 0;