+
+static int
+sysctl_waitq_set_nelem SYSCTL_HANDLER_ARGS
+{
+#pragma unused(oidp, arg1, arg2)
+ int nelem;
+
+ /* Read only */
+ if (req->newptr != USER_ADDR_NULL) {
+ return EPERM;
+ }
+
+ nelem = sysctl_helper_waitq_set_nelem();
+
+ return SYSCTL_OUT(req, &nelem, sizeof(nelem));
+}
+
+SYSCTL_PROC(_kern, OID_AUTO, n_ltable_entries, CTLFLAG_RD | CTLFLAG_LOCKED,
+ 0, 0, sysctl_waitq_set_nelem, "I", "ltable elementis currently used");
+
+
+#endif /* DEVELOPMENT || DEBUG */
+
+/*Remote Time api*/
+SYSCTL_NODE(_machdep, OID_AUTO, remotetime, CTLFLAG_RD | CTLFLAG_LOCKED, 0, "Remote time api");
+
+#if DEVELOPMENT || DEBUG
+#if CONFIG_MACH_BRIDGE_SEND_TIME
+extern _Atomic uint32_t bt_init_flag;
+extern uint32_t mach_bridge_timer_enable(uint32_t, int);
+
+SYSCTL_INT(_machdep_remotetime, OID_AUTO, bridge_timer_init_flag,
+ CTLFLAG_RD | CTLFLAG_LOCKED, &bt_init_flag, 0, "");
+
+static int sysctl_mach_bridge_timer_enable SYSCTL_HANDLER_ARGS
+{
+#pragma unused(oidp, arg1, arg2)
+ uint32_t value = 0;
+ int error = 0;
+ /* User is querying buffer size */
+ if (req->oldptr == USER_ADDR_NULL && req->newptr == USER_ADDR_NULL) {
+ req->oldidx = sizeof(value);
+ return 0;
+ }
+ if (bt_init_flag) {
+ if (req->newptr) {
+ int new_value = 0;
+ error = SYSCTL_IN(req, &new_value, sizeof(new_value));
+ if (error) {
+ return error;
+ }
+ if (new_value == 0 || new_value == 1) {
+ value = mach_bridge_timer_enable(new_value, 1);
+ } else {
+ return EPERM;
+ }
+ } else {
+ value = mach_bridge_timer_enable(0, 0);
+ }
+ }
+ error = SYSCTL_OUT(req, &value, sizeof(value));
+ return error;
+}
+
+SYSCTL_PROC(_machdep_remotetime, OID_AUTO, bridge_timer_enable,
+ CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_LOCKED,
+ 0, 0, sysctl_mach_bridge_timer_enable, "I", "");
+
+#endif /* CONFIG_MACH_BRIDGE_SEND_TIME */
+
+static int sysctl_mach_bridge_remote_time SYSCTL_HANDLER_ARGS
+{
+#pragma unused(oidp, arg1, arg2)
+ uint64_t ltime = 0, rtime = 0;
+ if (req->oldptr == USER_ADDR_NULL) {
+ req->oldidx = sizeof(rtime);
+ return 0;
+ }
+ if (req->newptr) {
+ int error = SYSCTL_IN(req, <ime, sizeof(ltime));
+ if (error) {
+ return error;
+ }
+ }
+ rtime = mach_bridge_remote_time(ltime);
+ return SYSCTL_OUT(req, &rtime, sizeof(rtime));
+}
+SYSCTL_PROC(_machdep_remotetime, OID_AUTO, mach_bridge_remote_time,
+ CTLTYPE_QUAD | CTLFLAG_RW | CTLFLAG_LOCKED,
+ 0, 0, sysctl_mach_bridge_remote_time, "Q", "");
+
+#endif /* DEVELOPMENT || DEBUG */
+
+#if CONFIG_MACH_BRIDGE_RECV_TIME
+extern struct bt_params bt_params_get_latest(void);
+
+static int sysctl_mach_bridge_conversion_params SYSCTL_HANDLER_ARGS
+{
+#pragma unused(oidp, arg1, arg2)
+ struct bt_params params = {};
+ if (req->oldptr == USER_ADDR_NULL) {
+ req->oldidx = sizeof(struct bt_params);
+ return 0;
+ }
+ if (req->newptr) {
+ return EPERM;
+ }
+ params = bt_params_get_latest();
+ return SYSCTL_OUT(req, ¶ms, MIN(sizeof(params), req->oldlen));
+}
+
+SYSCTL_PROC(_machdep_remotetime, OID_AUTO, conversion_params,
+ CTLTYPE_STRUCT | CTLFLAG_RD | CTLFLAG_LOCKED, 0,
+ 0, sysctl_mach_bridge_conversion_params, "S,bt_params", "");
+
+#endif /* CONFIG_MACH_BRIDGE_RECV_TIME */
+
+
+
+static int
+sysctl_kern_tcsm_available SYSCTL_HANDLER_ARGS
+{
+#pragma unused(oidp, arg1, arg2)
+ uint32_t value = machine_csv(CPUVN_CI) ? 1 : 0;
+
+ if (req->newptr) {
+ return EINVAL;
+ }
+
+ return SYSCTL_OUT(req, &value, sizeof(value));
+}
+SYSCTL_PROC(_kern, OID_AUTO, tcsm_available,
+ CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED | CTLFLAG_MASKED | CTLFLAG_ANYBODY,
+ 0, 0, sysctl_kern_tcsm_available, "I", "");
+
+
+static int
+sysctl_kern_tcsm_enable SYSCTL_HANDLER_ARGS
+{
+#pragma unused(oidp, arg1, arg2)
+ uint32_t soflags = 0;
+ uint32_t old_value = thread_get_no_smt() ? 1 : 0;
+
+ int error = SYSCTL_IN(req, &soflags, sizeof(soflags));
+ if (error) {
+ return error;
+ }
+
+ if (soflags && machine_csv(CPUVN_CI)) {
+ thread_set_no_smt(true);
+ machine_tecs(current_thread());
+ }
+
+ return SYSCTL_OUT(req, &old_value, sizeof(old_value));
+}
+SYSCTL_PROC(_kern, OID_AUTO, tcsm_enable,
+ CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_LOCKED | CTLFLAG_MASKED | CTLFLAG_ANYBODY,
+ 0, 0, sysctl_kern_tcsm_enable, "I", "");
+
+
+#if DEVELOPMENT || DEBUG
+extern void sysctl_task_set_no_smt(char no_smt);
+extern char sysctl_task_get_no_smt(void);
+
+static int
+sysctl_kern_sched_task_set_no_smt SYSCTL_HANDLER_ARGS
+{
+#pragma unused(oidp, arg1, arg2)
+ char buff[4];
+
+ int error = SYSCTL_IN(req, buff, 1);
+ if (error) {
+ return error;
+ }
+ char no_smt = buff[0];
+
+ if (!req->newptr) {
+ goto out;
+ }
+
+ sysctl_task_set_no_smt(no_smt);
+out:
+ no_smt = sysctl_task_get_no_smt();
+ buff[0] = no_smt;
+
+ return SYSCTL_OUT(req, buff, 1);
+}
+
+SYSCTL_PROC(_kern, OID_AUTO, sched_task_set_no_smt, CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_LOCKED | CTLFLAG_ANYBODY,
+ 0, 0, sysctl_kern_sched_task_set_no_smt, "A", "");
+
+static int
+sysctl_kern_sched_thread_set_no_smt(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
+{
+ int new_value, changed;
+ int old_value = thread_get_no_smt() ? 1 : 0;
+ int error = sysctl_io_number(req, old_value, sizeof(int), &new_value, &changed);
+
+ if (changed) {
+ thread_set_no_smt(!!new_value);
+ }
+
+ return error;
+}
+
+SYSCTL_PROC(_kern, OID_AUTO, sched_thread_set_no_smt,
+ CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_LOCKED | CTLFLAG_ANYBODY,
+ 0, 0, sysctl_kern_sched_thread_set_no_smt, "I", "");
+#endif