1227825Stheraven/*- 2227825Stheraven * Copyright (c) 2001 Jake Burkholder <jake@FreeBSD.org> 3227825Stheraven * All rights reserved. 4227825Stheraven * 5227825Stheraven * Redistribution and use in source and binary forms, with or without 6227825Stheraven * modification, are permitted provided that the following conditions 7227825Stheraven * are met: 8227825Stheraven * 1. Redistributions of source code must retain the above copyright 9227825Stheraven * notice, this list of conditions and the following disclaimer. 10227825Stheraven * 2. Redistributions in binary form must reproduce the above copyright 11227825Stheraven * notice, this list of conditions and the following disclaimer in the 12227825Stheraven * documentation and/or other materials provided with the distribution. 13227825Stheraven * 14227825Stheraven * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15227825Stheraven * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16227825Stheraven * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17227825Stheraven * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18227825Stheraven * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19227825Stheraven * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20227825Stheraven * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21227825Stheraven * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22227825Stheraven * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23227825Stheraven * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24227825Stheraven * SUCH DAMAGE. 25227825Stheraven * 26227825Stheraven * $FreeBSD: releng/10.2/sys/ia64/include/runq.h 208283 2010-05-19 00:23:10Z marcel $ 27227825Stheraven */ 28227825Stheraven 29227825Stheraven#ifndef _MACHINE_RUNQ_H_ 30227825Stheraven#define _MACHINE_RUNQ_H_ 31227825Stheraven 32227825Stheraven#define RQB_LEN (1UL) /* Number of priority status words. */ 33227825Stheraven#define RQB_L2BPW (6UL) /* Log2(sizeof(rqb_word_t) * NBBY)). */ 34227825Stheraven#define RQB_BPW (1UL<<RQB_L2BPW) /* Bits in an rqb_word_t. */ 35227825Stheraven 36227825Stheraven#define RQB_BIT(pri) (1UL << ((pri) & (RQB_BPW - 1))) 37227825Stheraven#define RQB_WORD(pri) ((pri) >> RQB_L2BPW) 38227825Stheraven 39227825Stheraven#define RQB_FFS(word) (__ffsl(word) - 1) 40227825Stheraven 41227825Stheraven/* 42227825Stheraven * Type of run queue status word. 43227825Stheraven */ 44227825Stheraventypedef uint64_t rqb_word_t; 45227825Stheraven 46227825Stheravenstatic __inline uint64_t 47227825Stheraven__popcnt(uint64_t bits) 48227825Stheraven{ 49227825Stheraven uint64_t result; 50227825Stheraven 51227825Stheraven __asm __volatile("popcnt %0=%1" : "=r" (result) : "r" (bits)); 52227825Stheraven return result; 53227825Stheraven} 54227825Stheraven 55227825Stheraven 56227825Stheravenstatic __inline int 57227825Stheraven__ffsl(u_long mask) 58241900Sdim{ 59227825Stheraven 60227825Stheraven if (__predict_false(mask == 0ul)) 61227825Stheraven return (0); 62261272Sdim return (__popcnt(mask ^ (mask - 1))); 63261272Sdim} 64227825Stheraven 65227825Stheraven#endif 66227825Stheraven