135c05a4fSAdrian Chadd.\" 294dab02dSAdrian Chadd.Dd October 23, 2016 335c05a4fSAdrian Chadd.Dt LIBRSS 3 435c05a4fSAdrian Chadd.Os 535c05a4fSAdrian Chadd.Sh NAME 635c05a4fSAdrian Chadd.Nm librss 735c05a4fSAdrian Chadd.Nd Provide Receive-side scaling awareness to userland applications 835c05a4fSAdrian Chadd.Sh LIBRARY 935c05a4fSAdrian Chadd.Lb librss 1035c05a4fSAdrian Chadd.Sh SYNOPSIS 1194dab02dSAdrian Chadd.In sys/param.h 1294dab02dSAdrian Chadd.In sys/cpuset.h 1335c05a4fSAdrian Chadd.In librss.h 1435c05a4fSAdrian Chadd.Ft struct rss_config * 1535c05a4fSAdrian Chadd.Fn rss_config_get "void" 1635c05a4fSAdrian Chadd.Ft void 1735c05a4fSAdrian Chadd.Fn rss_config_free "struct rss_config *cfg" 1835c05a4fSAdrian Chadd.Ft int 1935c05a4fSAdrian Chadd.Fn rss_config_get_bucket_count "struct rss_config *cfg" 2035c05a4fSAdrian Chadd.Ft int 2194dab02dSAdrian Chadd.Fn rss_get_bucket_cpuset "struct rss_config *rc" "rss_bucket_type_t btype" "int bucket" "cpuset_t *cs" 2294dab02dSAdrian Chadd.Ft int 2335c05a4fSAdrian Chadd.Fn rss_set_bucket_rebalance_cb "rss_bucket_rebalance_cb_t *cb" "void *cbdata" 2435c05a4fSAdrian Chadd.Ft int 2535c05a4fSAdrian Chadd.Fn rss_sock_set_recvrss "int fd" "int af" "int val" 2635c05a4fSAdrian Chadd.Sh DESCRIPTION 2735c05a4fSAdrian ChaddThe 2835c05a4fSAdrian Chadd.Nm 2935c05a4fSAdrian Chaddlibrary and the functions it provides are used for both fetching 3035c05a4fSAdrian Chaddthe system RSS configuration and interacting with RSS aware 3135c05a4fSAdrian Chaddsockets. 3235c05a4fSAdrian Chadd.Pp 3335c05a4fSAdrian ChaddApplications will typically call 3435c05a4fSAdrian Chadd.Fn rss_config_get 3535c05a4fSAdrian Chaddto fetch the current RSS configuration from the system and perform 3635c05a4fSAdrian Chaddinitial setup. 3735c05a4fSAdrian ChaddThis typically involves spawning worker threads, one per RSS bucket, 3835c05a4fSAdrian Chaddand optionally binding them to the per-bucket CPU set. 3935c05a4fSAdrian Chadd.Pp 4035c05a4fSAdrian ChaddThe 4135c05a4fSAdrian Chadd.Vt rss_config 4235c05a4fSAdrian Chaddstruct is defined as: 4335c05a4fSAdrian Chadd.Bd -literal 4435c05a4fSAdrian Chaddstruct rss_config { 4535c05a4fSAdrian Chadd int rss_ncpus; 4635c05a4fSAdrian Chadd int rss_nbuckets; 4735c05a4fSAdrian Chadd int rss_basecpu; 4835c05a4fSAdrian Chadd int *rss_bucket_map; 4935c05a4fSAdrian Chadd}; 5035c05a4fSAdrian Chadd.Ed 5135c05a4fSAdrian Chadd.Pp 5235c05a4fSAdrian ChaddApplications will typically use the 5335c05a4fSAdrian Chadd.Fn rss_config_get_bucket_count 5435c05a4fSAdrian Chaddfunction to fetch the number of RSS buckets, create one thread 5535c05a4fSAdrian Chaddper RSS bucket for RSS aware work, then one RSS aware socket to receive 5635c05a4fSAdrian ChaddUDP datagrams or TCP connections 5735c05a4fSAdrian Chaddin each particular RSS bucket / thread. 5835c05a4fSAdrian Chadd.Pp 5935c05a4fSAdrian ChaddThe 6035c05a4fSAdrian Chadd.Fn rss_get_bucket_cpuset 6135c05a4fSAdrian Chaddfunction sets the given cpuset up for the given 6235c05a4fSAdrian ChaddRSS bucket and behaviour. 6335c05a4fSAdrian ChaddTypically applications will wish to just query for 6435c05a4fSAdrian Chadd.Vt RSS_BUCKET_TYPE_KERNEL_ALL 6535c05a4fSAdrian Chaddunless they wish to potentially setup different 6635c05a4fSAdrian Chaddworker threads for transmit and receive. 6735c05a4fSAdrian Chadd.Pp 6835c05a4fSAdrian ChaddThe 6935c05a4fSAdrian Chadd.Vt rss_bucket_type_t 7035c05a4fSAdrian Chaddenum is defined as: 7135c05a4fSAdrian Chadd.Bd -literal 7235c05a4fSAdrian Chaddtypedef enum { 7335c05a4fSAdrian Chadd RSS_BUCKET_TYPE_NONE = 0, 7435c05a4fSAdrian Chadd RSS_BUCKET_TYPE_KERNEL_ALL = 1, 7535c05a4fSAdrian Chadd RSS_BUCKET_TYPE_KERNEL_TX = 2, 7635c05a4fSAdrian Chadd RSS_BUCKET_TYPE_KERNEL_RX = 3, 7735c05a4fSAdrian Chadd RSS_BUCKET_TYPE_MAX = 3, 7835c05a4fSAdrian Chadd} rss_bucket_type_t; 7935c05a4fSAdrian Chadd.Ed 8035c05a4fSAdrian Chadd.Pp 8135c05a4fSAdrian ChaddThe rebalance callback 8235c05a4fSAdrian Chadd.Vt rss_bucket_rebalance_cb_t 8335c05a4fSAdrian Chaddis defined as: 8435c05a4fSAdrian Chadd.Bd -literal 8535c05a4fSAdrian Chaddtypedef void rss_bucket_rebalance_cb_t(void *arg); 8635c05a4fSAdrian Chadd.Ed 8735c05a4fSAdrian Chadd.Pp 8835c05a4fSAdrian ChaddThe 8935c05a4fSAdrian Chadd.Fn rss_set_bucket_rebalance_cb 9035c05a4fSAdrian Chaddfunction sets an optional callback that will be called if the kernel 9135c05a4fSAdrian Chaddrebalances RSS buckets. 9235c05a4fSAdrian ChaddThis is intended as a future expansion to rebalance buckets rather than 9335c05a4fSAdrian Chaddreprogram the RSS key, so typically the only work to be performed 9435c05a4fSAdrian Chaddis to rebind worker threads to an updated cpuset. 9535c05a4fSAdrian Chadd.Pp 9635c05a4fSAdrian ChaddOnce RSS setup is completed, 9735c05a4fSAdrian Chadd.Fn rss_config_free 9835c05a4fSAdrian Chaddis called to free the RSS configuration structure. 9935c05a4fSAdrian Chadd.Pp 10035c05a4fSAdrian ChaddIf 10135c05a4fSAdrian Chadd.Vt val 10235c05a4fSAdrian Chaddis set to 1, the socket can be placed in an RSS bucket and will only accept 10335c05a4fSAdrian Chadddatagrams (for UDP) or connections (for TCP) that are received for that 10435c05a4fSAdrian ChaddRSS bucket. 10535c05a4fSAdrian ChaddIf set to 0, the socket is placed in the default PCB and will see 10635c05a4fSAdrian Chadddatagrams/connections that are not initially consumed by a PCB aware 10735c05a4fSAdrian Chaddsocket. 10835c05a4fSAdrian Chadd.Pp 10935c05a4fSAdrian ChaddThe 11035c05a4fSAdrian Chadd.Fn rss_sock_set_recvrss 11135c05a4fSAdrian Chaddfunction enables or disables receiving RSS related information 112*8b92fa1cSGraham Percivalas socket options in 113*8b92fa1cSGraham Percival.Xr recvmsg 2 11435c05a4fSAdrian Chaddcalls. 11535c05a4fSAdrian Chadd.Pp 11635c05a4fSAdrian ChaddWhen enabled, UDP datagrams will have a message with the 11735c05a4fSAdrian Chadd.Vt IP_RECVFLOWID 11835c05a4fSAdrian Chaddoption indicating the 32-bit receive flowid as a uint32_t, 11935c05a4fSAdrian Chaddand the 12035c05a4fSAdrian Chadd.Vt IP_RECVRSSBUCKETID 12135c05a4fSAdrian Chaddoption indicating the 32 bit RSS bucket id as a uint32_t. 12235c05a4fSAdrian Chadd.Sh ERRORS 12335c05a4fSAdrian ChaddThe functions return either <0 or NULL as appropriate upon error. 12435c05a4fSAdrian Chadd.Sh HISTORY 12535c05a4fSAdrian ChaddThe 12635c05a4fSAdrian Chadd.Xr librss.3 12735c05a4fSAdrian Chaddlibrary first appeared in 12835c05a4fSAdrian Chadd.Fx 11.0 . 12935c05a4fSAdrian Chadd.Sh AUTHORS 13035c05a4fSAdrian Chadd.An Adrian Chadd Aq Mt adrian@FreeBSD.org 13135c05a4fSAdrian Chadd.Sh BUGS 13235c05a4fSAdrian ChaddThere is currently no kernel mechanism to rebalance the RSS bucket to CPU 13335c05a4fSAdrian Chaddmapping, and so the callback mechanism is a no-op. 134