Loading...
iokit/Kernel/IOPerfControl.cpp xnu-12377.121.6 xnu-8019.41.5
--- xnu/xnu-12377.121.6/iokit/Kernel/IOPerfControl.cpp
+++ xnu/xnu-8019.41.5/iokit/Kernel/IOPerfControl.cpp
@@ -7,9 +7,6 @@
 #include <stdatomic.h>
 
 #include <kern/thread_group.h>
-#include <kern/task.h>
-#include <sys/coalition.h>
-#include <kern/coalition.h>
 
 #undef super
 #define super OSObject
@@ -147,36 +144,14 @@
 	super::free();
 }
 
-void
-IOPerfControlClient::setDeviceType(IOPCDeviceType newDeviceType)
-{
-	if (newDeviceType >= IOPCDeviceTypeMax) {
-		panic("unknown device type %d", newDeviceType);
-	}
-
-	if (deviceType != IOPCDeviceTypeUnknown) {
-		panic("deviceType already set to %d", deviceType);
-	}
-
-	deviceType = newDeviceType;
-}
-
-
 IOPerfControlClient *
-IOPerfControlClient::copyClientForDeviceType(IOService *driver, uint64_t maxWorkCapacity, IOPCDeviceType deviceType)
+IOPerfControlClient::copyClient(IOService *driver, uint64_t maxWorkCapacity)
 {
 	IOPerfControlClient *client = new IOPerfControlClient;
 	if (!client || !client->init(driver, maxWorkCapacity)) {
 		panic("could not create IOPerfControlClient");
 	}
-	client->setDeviceType(deviceType);
 	return client;
-}
-
-IOPerfControlClient *
-IOPerfControlClient::copyClient(IOService *driver, uint64_t maxWorkCapacity)
-{
-	return copyClientForDeviceType(driver, maxWorkCapacity, IOPCDeviceTypeUnknown);
 }
 
 /* Convert the per driver token into a globally unique token for the performance
@@ -192,26 +167,6 @@
 	return token | (static_cast<uint64_t>(driverIndex) << kWorkTableIndexBits);
 }
 
-/* Accounting resources used in a work item to the containing coalition.
- * Contigent upon the PerfController signaling that it wants resource accounting
- * in the registerDevice()/registerDriverDevice calls. More device types can
- * be added here in the future.
- */
-void
-IOPerfControlClient::accountResources(coalition_t coal, PerfControllerInterface::PerfDeviceID device_type, PerfControllerInterface::ResourceAccounting *resources)
-{
-	switch (device_type) {
-	case PerfControllerInterface::PerfDeviceID::kANE:
-		if (coal != nullptr) {
-			coalition_update_ane_stats(coal, resources->mach_time_delta, resources->energy_nj_delta);
-		}
-		break;
-
-	default:
-		assertf(false, "Unexpected device type for IOPerfControlClient::accountResources: %llu", static_cast<uint64_t>(device_type));
-	}
-}
-
 /* With this implementation, tokens returned to the driver differ from tokens
  * passed to the performance controller. This implementation has the nice
  * property that tokens returns to the driver will aways be between 1 and
@@ -234,12 +189,6 @@
 		if (workTable[index].thread_group == nullptr) {
 			thread_group_retain(thread_group);
 			workTable[index].thread_group = thread_group;
-			if (clientData.driverState.resource_accounting) {
-				auto *coalition = task_get_coalition(current_task(), COALITION_TYPE_RESOURCE);
-				assert(coalition != nullptr);
-				coalition_retain(coalition);
-				workTable[index].coal = coalition;
-			}
 			token = index;
 			// next integer between 1 and workTableLength - 1
 			workTableNextIndex = (index % (workTableLength - 1)) + 1;
@@ -279,7 +228,6 @@
 
 	auto &entry = workTable[token];
 	auto *thread_group = entry.thread_group;
-	auto *coal = entry.coal;
 	bzero(&entry, sizeof(entry));
 	workTableNextIndex = token;
 
@@ -288,9 +236,6 @@
 	// This can call into the performance controller if the last reference is dropped here. Are we sure
 	// the driver isn't holding any locks? If not, we may want to async this to another context.
 	thread_group_release(thread_group);
-	if (coal != nullptr) {
-		coalition_release(coal);
-	}
 #endif
 }
 
@@ -523,16 +468,7 @@
 		.started = entry->started,
 		.driver_state = &clientData.driverState
 	};
-
-	if (shared->interface.version >= PERFCONTROL_INTERFACE_VERSION_4) {
-		PerfControllerInterface::ResourceAccounting resources;
-		shared->interface.workEndWithResources(device, tokenToGlobalUniqueToken(token), &state, args, &resources, done);
-		if (clientData.driverState.resource_accounting) {
-			accountResources(workTable[token].coal, clientData.driverState.device_type, &resources);
-		}
-	} else {
-		shared->interface.workEnd(device, tokenToGlobalUniqueToken(token), &state, args, done);
-	}
+	shared->interface.workEnd(device, tokenToGlobalUniqueToken(token), &state, args, done);
 
 	if (done) {
 		deallocateToken(token);
@@ -551,7 +487,6 @@
 public:
 	uint64_t id;
 	struct thread_group *thread_group;
-	coalition_t coal;
 	bool started;
 	uint8_t perfcontrol_data[32];
 
@@ -577,7 +512,6 @@
 IOPerfControlWorkContext::reset()
 {
 	thread_group = nullptr;
-	coal = nullptr;
 	started = false;
 	bzero(perfcontrol_data, sizeof(perfcontrol_data));
 }
@@ -586,7 +520,6 @@
 IOPerfControlWorkContext::free()
 {
 	assertf(thread_group == nullptr, "IOPerfControlWorkContext ID %llu being released without calling workEnd!\n", id);
-	assertf(coal == nullptr, "IOPerfControlWorkContext ID %llu being released without calling workEnd!\n", id);
 	super::free();
 }
 
@@ -666,12 +599,6 @@
 	}
 
 	work_context->thread_group = thread_group_retain(thread_group);
-	if (clientData.driverState.resource_accounting) {
-		auto *coalition = task_get_coalition(current_task(), COALITION_TYPE_RESOURCE);
-		assert(coalition != nullptr);
-		work_context->coal = coalition;
-		coalition_retain(coalition);
-	}
 
 	state.work_data = &work_context->perfcontrol_data;
 	state.work_data_size = sizeof(work_context->perfcontrol_data);
@@ -764,21 +691,10 @@
 		.driver_state = &clientData.driverState
 	};
 
-	if (shared->interface.version >= PERFCONTROL_INTERFACE_VERSION_4) {
-		PerfControllerInterface::ResourceAccounting resources;
-		shared->interface.workEndWithResources(device, work_context->id, &state, args, &resources, done);
-		if (clientData.driverState.resource_accounting) {
-			accountResources(work_context->coal, clientData.driverState.device_type, &resources);
-		}
-	} else {
-		shared->interface.workEnd(device, work_context->id, &state, args, done);
-	}
+	shared->interface.workEnd(device, work_context->id, &state, args, done);
 
 	if (done) {
 		thread_group_release(work_context->thread_group);
-		if (work_context->coal != nullptr) {
-			coalition_release(work_context->coal);
-		}
 		work_context->reset();
 	} else {
 		work_context->started = false;
@@ -788,30 +704,6 @@
 #else
 	return;
 #endif
-}
-
-IOReturn
-IOPerfControlClient::querySubmitterRole(IOService *device, task_t clientTask, uint32_t* role_out)
-{
-	IOReturn result = kIOReturnNotFound;
-
-	uint32_t role;
-
-	switch (deviceType) {
-	case IOPCDeviceTypeGPU:
-		role = task_get_gpu_role(clientTask);
-
-		KDBG(IMPORTANCE_CODE(IMP_QUERY_GPU_ROLE, 0), role);
-
-		*role_out = role;
-
-		result = kIOReturnSuccess;
-		break;
-	default:
-		result = kIOReturnNotFound;
-	}
-
-	return result;
 }
 
 IOReturn
@@ -844,11 +736,6 @@
 			assert(pci->registerDriverDevice && pci->unregisterDriverDevice);
 			shared->interface.registerDriverDevice = pci->registerDriverDevice;
 			shared->interface.unregisterDriverDevice = pci->unregisterDriverDevice;
-		}
-
-		if (pci->version >= PERFCONTROL_INTERFACE_VERSION_4) {
-			assert(pci->workEndWithResources);
-			shared->interface.workEndWithResources = pci->workEndWithResources;
 		}
 
 		result = kIOReturnSuccess;