examples/performance-thread: convert license to SPDX
[dpdk.git] / examples / performance-thread / common / lthread_sched.c
index 3fad768..38ca0c4 100644 (file)
@@ -1,65 +1,9 @@
-/*-
- *   BSD LICENSE
- *
- *   Copyright(c) 2015 Intel Corporation. All rights reserved.
- *   All rights reserved.
- *
- *   Redistribution and use in source and binary forms, with or without
- *   modification, are permitted provided that the following conditions
- *   are met:
- *
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- *       notice, this list of conditions and the following disclaimer in
- *       the documentation and/or other materials provided with the
- *       distribution.
- *     * Neither the name of Intel Corporation nor the names of its
- *       contributors may be used to endorse or promote products derived
- *       from this software without specific prior written permission.
- *
- *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
 /*
- * Some portions of this software is derived from the
- * https://github.com/halayli/lthread which carrys the following license.
- *
- * Copyright (C) 2012, Hasan Alayli <halayli@gmail.com>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
+ * SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2015 Intel Corporation.
+ * Copyright 2012 Hasan Alayli <halayli@gmail.com>
  */
 
-
 #define RTE_MEM 1
 
 #include <stdio.h>
@@ -76,7 +20,6 @@
 #include <sys/mman.h>
 #include <sched.h>
 
-#include <rte_config.h>
 #include <rte_prefetch.h>
 #include <rte_per_lcore.h>
 #include <rte_atomic.h>
@@ -118,8 +61,7 @@ uint64_t diag_mask;
 
 
 /* constructor */
-void lthread_sched_ctor(void) __attribute__ ((constructor));
-void lthread_sched_ctor(void)
+RTE_INIT(lthread_sched_ctor)
 {
        memset(schedcore, 0, sizeof(schedcore));
        rte_atomic16_init(&num_schedulers);
@@ -269,7 +211,7 @@ struct lthread_sched *_lthread_sched_create(size_t stack_size)
        struct lthread_sched *new_sched;
        unsigned lcoreid = rte_lcore_id();
 
-       LTHREAD_ASSERT(stack_size <= LTHREAD_MAX_STACK_SIZE);
+       RTE_ASSERT(stack_size <= LTHREAD_MAX_STACK_SIZE);
 
        if (stack_size == 0)
                stack_size = LTHREAD_MAX_STACK_SIZE;
@@ -370,8 +312,8 @@ void lthread_scheduler_shutdown_all(void)
 /*
  * Resume a suspended lthread
  */
-static inline void
-_lthread_resume(struct lthread *lt) __attribute__ ((always_inline));
+static __rte_always_inline void
+_lthread_resume(struct lthread *lt);
 static inline void _lthread_resume(struct lthread *lt)
 {
        struct lthread_sched *sched = THIS_SCHED;
@@ -462,10 +404,10 @@ _sched_timer_cb(struct rte_timer *tim, void *arg)
  */
 static inline int _lthread_sched_isdone(struct lthread_sched *sched)
 {
-       return ((sched->run_flag == 0) &&
+       return (sched->run_flag == 0) &&
                        (_lthread_queue_empty(sched->ready)) &&
                        (_lthread_queue_empty(sched->pready)) &&
-                       (sched->nb_blocked_threads == 0));
+                       (sched->nb_blocked_threads == 0);
 }
 
 /*
@@ -563,11 +505,14 @@ void lthread_run(void)
  * Return the scheduler for this lcore
  *
  */
-struct lthread_sched *_lthread_sched_get(int lcore_id)
+struct lthread_sched *_lthread_sched_get(unsigned int lcore_id)
 {
-       if (lcore_id > LTHREAD_MAX_LCORES)
-               return NULL;
-       return schedcore[lcore_id];
+       struct lthread_sched *res = NULL;
+
+       if (lcore_id < LTHREAD_MAX_LCORES)
+               res = schedcore[lcore_id];
+
+       return res;
 }
 
 /*
@@ -579,10 +524,9 @@ int lthread_set_affinity(unsigned lcoreid)
        struct lthread *lt = THIS_LTHREAD;
        struct lthread_sched *dest_sched;
 
-       if (unlikely(lcoreid > LTHREAD_MAX_LCORES))
+       if (unlikely(lcoreid >= LTHREAD_MAX_LCORES))
                return POSIX_ERRNO(EINVAL);
 
-
        DIAG_EVENT(lt, LT_DIAG_LTHREAD_AFFINITY, lcoreid, 0);
 
        dest_sched = schedcore[lcoreid];