public void AddMessagePath(MessagePath <TMessage> messagePath) { lock (_locker) { if (typeof(ICmd).IsAssignableFrom(typeof(TMessage))) { bool isExist = _messagePaths.Any(a => messagePath.PathId == a.PathId); if (isExist) { /// <see cref="ICmd"/> throw new Exception($"一种命令只应被一个处理器处理:{typeof(TMessage).Name}"); } } else if (messagePath.Location != AnonymousMessagePath.Location && _messagePaths.Any(a => a.Path == messagePath.Path && a.PathId == messagePath.PathId)) { NTMinerConsole.DevWarn(() => $"重复的路径:{messagePath.Path} {messagePath.Description}"); } _messagePaths.Add(messagePath); } }
/// <summary> /// 这里挺绕,逻辑是父类通过回调函数的参数声明一个接收矿工列表的方法,然后由 /// 子类调用该基类方法时传入矿工列表,从而父类收到了来自子类的矿工列表。因为 /// 该基类有两个子类,一个子类的数据源是redis一个子类的数据源是litedb。 /// </summary> /// <param name="isPull">内网群控传true,外网群控传false</param> /// <param name="getDatas"></param> public ClientDataSetBase(bool isPull, Action <Action <IEnumerable <ClientData> > > getDatas) { _isPull = isPull; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); getDatas(clientDatas => { foreach (var clientData in clientDatas) { _dicByObjectId[clientData.Id] = clientData; _dicByClientId[clientData.ClientId] = clientData; } InitedOn = DateTime.Now; IsReadied = true; stopwatch.Stop(); NTMinerConsole.UserLine($"矿机集就绪,耗时 {stopwatch.GetElapsedSeconds().ToString("f2")} 秒", isPull ? MessageType.Debug : MessageType.Ok); VirtualRoot.RaiseEvent(new ClientSetInitedEvent()); }); }
public ServerStateResponse GetServerState([FromBody] JsonFileVersionRequest request) { ServerStateResponse serverState = ServerStateResponse.Empty; if (request != null) { serverState = AppRoot.GetServerStateResponse(request.Key); if (request.ClientId != Guid.Empty) { var clientData = AppRoot.ClientDataSet.GetByClientId(request.ClientId); if (clientData != null && !string.IsNullOrEmpty(clientData.MACAddress)) { serverState.NeedReClientId = request.MACAddress.All(a => !clientData.MACAddress.Contains(a)); NTMinerConsole.UserWarn($"重复的网卡地址:{string.Join(",", request.MACAddress)}"); } } } return(serverState); }
public uint GetTemperature(int gpuIndex) { if (!NvmlInit() || !TryGetNvmlDevice(gpuIndex, out nvmlDevice nvmlDevice)) { return(0); } uint temp = 0; try { var r = NvmlNativeMethods.nvmlDeviceGetTemperature(nvmlDevice, nvmlTemperatureSensors.Gpu, ref temp); if (r != nvmlReturn.Success) { NTMinerConsole.DevError(() => $"{nameof(NvmlNativeMethods.nvmlDeviceGetTemperature)} {r.ToString()}"); } } catch { } return(temp); }
/// <summary> /// 清理掉在给定的时间内未活跃的客户端 /// </summary> /// <param name="seconds"></param> private void ClearDeath() { // 客户端每20秒ping一次服务端,所以如果2分钟未活跃可以视为不在线了 int seconds = 120; DateTime activeOn = DateTime.Now.AddSeconds(-seconds); DateTime doubleActiveOn = activeOn.AddSeconds(-seconds); Dictionary <string, TSession> toRemoves; lock (_locker) { toRemoves = _dicByWsSessionId.Values.Where(a => a != null && a.ActiveOn <= activeOn).ToDictionary(a => a.WsSessionId, a => a); } List <WebSocket> toCloseWses = new List <WebSocket>(); foreach (var wsSession in WsSessionManager.Sessions) { if (toRemoves.ContainsKey(wsSession.ID)) { toCloseWses.Add(wsSession.Context.WebSocket); } } foreach (var ws in toCloseWses) { try { ws.CloseAsync(CloseStatusCode.Normal, $"{seconds.ToString()}秒内未活跃"); } catch { } } // 断开Ws连接时的OnClose事件中会移除已断开连接的会话,但OnClose事件是由WebSocket的库触发 // 的不是由我触发的,暂时没有深究这个库是否确定会触发OnClose事件所以这里加了个防护逻辑 foreach (var toRemove in toRemoves) { if (toRemove.Value.ActiveOn <= doubleActiveOn) { RemoveByWsSessionId(toRemove.Key); } } if (toRemoves.Count > 0) { NTMinerConsole.UserWarn($"周期清理不活跃的{_sessionType.Name},清理了 {toRemoves.Count.ToString()}/{toRemoves.Count.ToString()} 条"); } }
public int GetTemperature(int gpuIndex) { try { if (!TryGpuAdapterIndex(gpuIndex, out int adapterIndex)) { return(0); } ADLTemperature info = new ADLTemperature(); var r = AdlNativeMethods.ADL_Overdrive5_Temperature_Get(adapterIndex, 0, ref info); if (r < AdlStatus.ADL_OK) { NTMinerConsole.DevError(() => $"{nameof(AdlNativeMethods.ADL_Overdrive5_Temperature_Get)} {r.ToString()}"); return(0); } return((int)(0.001f * info.Temperature)); } catch { return(0); } }
public void MoveWindow(int marginLeft, int marginTop, int width, int height) { if (!this.IsLoaded) { return; } if (width < 0) { width = 0; } if (_marginLeft == marginLeft && _marginTop == marginTop && _height == height && _width == width) { return; } _marginLeft = marginLeft; _marginTop = marginTop; _height = height; _width = width; NTMinerConsole.MoveWindow(marginLeft, marginTop, width, height, true); }
public ulong GetTotalMemory(int gpuIndex) { try { if (!TryGpuAdapterIndex(gpuIndex, out int adapterIndex)) { return(0); } ADLMemoryInfo info = new ADLMemoryInfo(); var r = AdlNativeMethods.ADL_Adapter_MemoryInfo_Get(adapterIndex, ref info); if (r < AdlStatus.ADL_OK) { NTMinerConsole.DevError(() => $"{nameof(AdlNativeMethods.ADL_Adapter_MemoryInfo_Get)} {r.ToString()}"); return(0); } return(info.MemorySize); } catch { return(0); } }
public WsServerNodeAddressSet(IWsServerNodeRedis wsServerNodeRedis, IWsServerNodeMqSender wsServerNodeMqSender) : base(wsServerNodeRedis) { _wsServerNodeRedis = wsServerNodeRedis; _wsServerNodeMqSender = wsServerNodeMqSender; VirtualRoot.BuildOnecePath <WebSocketServerStatedEvent>("WebSocket服务启动后上报节点信息,获取节点列表", LogEnum.UserConsole, path: _ => { ReportNodeAsync(callback: () => { base.Init(callback: () => { NTMinerConsole.UserOk("Ws服务器节点地址集初始化完成"); VirtualRoot.RaiseEvent(new WsServerNodeAddressSetInitedEvent()); }); _wsServerNodeMqSender.SendWsServerNodeAdded(ServerRoot.HostConfig.ThisServerAddress); }); VirtualRoot.BuildEventPath <Per10SecondEvent>("节点呼吸", LogEnum.UserConsole, path: message => { ReportNodeAsync(); }, this.GetType()); VirtualRoot.BuildEventPath <Per1MinuteEvent>("打扫", LogEnum.DevConsole, path: message => { VirtualRoot.RaiseEvent(new CleanTimeArrivedEvent(AsEnumerable().ToArray())); }, this.GetType()); }, PathId.Empty, this.GetType()); }
public Version GetDriverVersion() { ADLVersionsInfoX2 info = new ADLVersionsInfoX2(); try { var r = AdlNativeMethods.ADL2_Graphics_VersionsX2_Get(context, ref info); if (r < AdlStatus.ADL_OK) { NTMinerConsole.DevError(() => $"{nameof(AdlNativeMethods.ADL2_Graphics_VersionsX2_Get)} {r.ToString()}"); } if (string.IsNullOrEmpty(info.strCrimsonVersion) || !Version.TryParse(info.strCrimsonVersion, out Version v)) { return(new Version()); } return(v); } catch { return(new Version()); } }
private void ReportNodeAsync(Action callback = null) { WsServerNodeState nodeState = null; try { int minerClientWsSessionCount = 0; int minerStudioWsSessionCount = 0; minerClientWsSessionCount = WsRoot.MinerClientSessionSet.WsSessionManager.Count; minerStudioWsSessionCount = WsRoot.MinerStudioSessionSet.WsSessionManager.Count; var ram = Windows.Ram.Instance; var cpu = Windows.Cpu.Instance; nodeState = new WsServerNodeState { Address = ServerRoot.HostConfig.ThisServerAddress, Description = string.Empty, MinerClientSessionCount = WsRoot.MinerClientSessionSet.Count, MinerStudioSessionCount = WsRoot.MinerStudioSessionSet.Count, MinerClientWsSessionCount = minerClientWsSessionCount, MinerStudioWsSessionCount = minerStudioWsSessionCount, Cpu = cpu.ToData(), TotalPhysicalMemory = ram.TotalPhysicalMemory, AvailablePhysicalMemory = ram.AvailablePhysicalMemory, OSInfo = Windows.OS.Instance.OsInfo, CpuPerformance = cpu.GetTotalCpuUsage(), ProcessMemoryMb = VirtualRoot.ProcessMemoryMb }; } catch (Exception e) { Logger.ErrorDebugLine(e); } _wsServerNodeRedis.SetAsync(nodeState).ContinueWith(t => { if (t.Exception != null) { NTMinerConsole.UserFail("呼吸失败:" + t.Exception.Message); } else { NTMinerConsole.UserOk("呼吸成功"); } callback?.Invoke(); }); }
private void CreateProcessAsync() { Task.Factory.StartNew(() => { lock (_locker) { try { // 清理除当前外的Temp/Kernel Cleaner.Instance.Clear(); if (IsTestUserName) { NTMinerConsole.UserWarn($"您正在使用开源矿工的测试账号挖矿,正常挖矿时请确保使用您自己的账号挖矿。"); } if (IsTestWallet) { NTMinerConsole.UserWarn($"您正在使用开源矿工的测试钱包地址挖矿,正常挖矿时请确保使用您自己的钱包地址挖矿。"); } NTMinerConsole.UserOk("场地打扫完毕"); // 应用超频 if (NTMinerContext.Instance.GpuProfileSet.IsOverClockEnabled(MainCoin.GetId())) { NTMinerConsole.UserWarn("应用超频,如果CPU性能较差耗时可能超过1分钟,请耐心等待"); var cmd = new CoinOverClockCommand(coinId: MainCoin.GetId()); AddOnecePath <CoinOverClockDoneEvent>("超频完成后继续流程", LogEnum.DevConsole, pathId: cmd.MessageId, location: this.GetType(), message => { // pathId是唯一的,从而可以断定该消息一定是因为该命令而引发的 ContinueCreateProcess(); }); // 超频是在另一个线程执行的,因为N卡超频当cpu性能非常差时较耗时 VirtualRoot.Execute(cmd); } else { ContinueCreateProcess(); } } catch (Exception e) { Logger.ErrorDebugLine(e); NTMinerConsole.UserFail("挖矿内核启动失败,如果有杀毒软件,请关闭杀毒软件,因为大部分挖矿内核会被杀毒软件删除。"); } } }); }
public OverClockRange GetClockRange(int gpuIndex) { OverClockRange result = new OverClockRange(gpuIndex); try { if (!TryGetAtiGpu(gpuIndex, out ATIGPU gpuInfo)) { return(result); } GetTempLimitAndPowerLimit(gpuIndex, out int powerLimit, out int tempLimit); GetClockAndVolt(gpuIndex, out int memoryClock, out int memoryiVddc, out int coreClock, out int coreiVddc); result.PowerCurr = powerLimit; result.TempCurr = tempLimit; result.MemoryClockDelta = memoryClock; result.MemoryVoltage = memoryiVddc; result.CoreClockDelta = coreClock; result.CoreVoltage = coreiVddc; result.CoreClockMin = gpuInfo.CoreClockMin; result.CoreClockMax = gpuInfo.CoreClockMax; result.MemoryClockMin = gpuInfo.MemoryClockMin; result.MemoryClockMax = gpuInfo.MemoryClockMax; result.PowerMin = gpuInfo.PowerMin; result.PowerMax = gpuInfo.PowerMax; result.PowerDefault = gpuInfo.PowerDefault; result.TempLimitMin = gpuInfo.TempLimitMin; result.TempLimitMax = gpuInfo.TempLimitMax; result.TempLimitDefault = gpuInfo.TempLimitDefault; result.VoltMin = gpuInfo.VoltMin; result.VoltMax = gpuInfo.VoltMax; result.VoltDefault = gpuInfo.VoltDefault; result.FanSpeedMin = gpuInfo.FanSpeedMin; result.FanSpeedMax = gpuInfo.FanSpeedMax; #if DEBUG NTMinerConsole.DevDebug(() => $"GetClockRange {result.ToString()}"); #endif } catch (Exception e) { Logger.ErrorDebugLine(e); } return(result); }
/// <summary> /// /// </summary> private void Snapshot(DateTime now) { InitOnece(); try { var coinSnapshots = VirtualRoot.CreateCoinSnapshots(_isPull, now, _clientSet.AsEnumerable().ToArray(), out int onlineCount, out int miningCount); _clientSet.ClientCount.Update(onlineCount, miningCount); if (coinSnapshots.Count > 0) { _dataList.AddRange(coinSnapshots); using (LiteDatabase db = CreateReportDb()) { var col = db.GetCollection <CoinSnapshotData>(); col.Insert(coinSnapshots); } NTMinerConsole.UserLine("拍摄快照" + coinSnapshots.Count + "张,快照时间戳:" + now.ToString("yyyy-MM-dd HH:mm:ss fff"), _isPull ? MessageType.Debug : MessageType.Info); } } catch (Exception e) { Logger.ErrorDebugLine(e); } }
public uint GetPowerUsage(int gpuIndex) { if (!TryGpuAdapterIndex(gpuIndex, out int adapterIndex)) { return(0); } int power = 0; try { var r = AdlNativeMethods.ADL2_Overdrive6_CurrentPower_Get(context, adapterIndex, 0, ref power); if (r < AdlStatus.ADL_OK) { NTMinerConsole.DevError(() => $"{nameof(AdlNativeMethods.ADL2_Overdrive6_CurrentPower_Get)} {r.ToString()}"); return(0); } return((uint)(power / 256.0)); } catch { } return(0); }
public int GetTempLimit(int gpuIndex) { if (!TryGpuAdapterIndex(gpuIndex, out int adapterIndex)) { return(0); } ADLODNPowerLimitSetting info = new ADLODNPowerLimitSetting(); try { var r = AdlNativeMethods.ADL2_OverdriveN_PowerLimit_Get(context, adapterIndex, ref info); if (r < AdlStatus.ADL_OK) { NTMinerConsole.DevError(() => $"{nameof(AdlNativeMethods.ADL2_OverdriveN_PowerLimit_Get)} {r.ToString()}"); return(0); } return(info.iMaxOperatingTemperature); } catch { return(0); } }
/// <summary> /// 这里挺绕,逻辑是由父类向子类传入一个接收一个矿工列表的方法,然后由子类调用该方法时传入矿工列表,从而父类收到了来自子类的矿工列表。 /// </summary> /// <param name="isPull"></param> /// <param name="getDatas"></param> public ClientDataSetBase(bool isPull, Action <Action <IEnumerable <ClientData> > > getDatas) { _isPull = isPull; getDatas(datas => { InitedOn = DateTime.Now; IsReadied = true; foreach (var item in datas) { if (!_dicByObjectId.ContainsKey(item.Id)) { _dicByObjectId.Add(item.Id, item); } if (!_dicByClientId.ContainsKey(item.ClientId)) { _dicByClientId.Add(item.ClientId, item); } } NTMinerConsole.UserLine("矿机集就绪", isPull ? MessageType.Debug : MessageType.Ok); VirtualRoot.RaiseEvent(new ClientSetInitedEvent()); }); }
public bool SetTempLimit(int gpuIndex, int value) { if (!TryGetAtiGpu(gpuIndex, out ATIGPU gpu)) { return(false); } try { bool isAutoModel = value == 0; if (gpu.OverdriveVersion < 8) { ADLODNPowerLimitSetting info = new ADLODNPowerLimitSetting(); var r = AdlNativeMethods.ADL2_OverdriveN_PowerLimit_Get(_context, gpu.AdapterIndex, out info); if (r < AdlStatus.ADL_OK) { NTMinerConsole.DevError(() => $"{nameof(AdlNativeMethods.ADL2_OverdriveN_PowerLimit_Get)} {r.ToString()}"); return(false); } info.iMode = isAutoModel ? AdlConst.ODNControlType_Auto : AdlConst.ODNControlType_Manual; info.iMaxOperatingTemperature = isAutoModel ? 0 : value; r = AdlNativeMethods.ADL2_OverdriveN_PowerLimit_Set(_context, gpu.AdapterIndex, ref info); if (r < AdlStatus.ADL_OK) { NTMinerConsole.DevError(() => $"{nameof(AdlNativeMethods.ADL2_OverdriveN_PowerLimit_Set)} {r.ToString()}"); return(false); } } else { if (GetOD8CurrentSetting(gpu.AdapterIndex, out ADLOD8CurrentSetting odCurrentSetting)) { SetOD8Range(gpu.ADLOD8InitSetting, odCurrentSetting, gpu.AdapterIndex, ADLOD8SettingId.OD8_OPERATING_TEMP_MAX, isAutoModel, value); } } return(true); } catch (Exception e) { Logger.ErrorDebugLine(e); return(false); } }
private uint GetFanSpeed(int gpuIndex) { try { if (!TryGpuAdapterIndex(gpuIndex, out int adapterIndex)) { return(0); } ADLFanSpeedValue info = new ADLFanSpeedValue { SpeedType = AdlConst.ADL_DL_FANCTRL_SPEED_TYPE_PERCENT }; var r = AdlNativeMethods.ADL_Overdrive5_FanSpeed_Get(adapterIndex, 0, ref info); if (r < AdlStatus.ADL_OK) { NTMinerConsole.DevError(() => $"{nameof(AdlNativeMethods.ADL_Overdrive5_FanSpeed_Get)} {r.ToString()}"); return(0); } return((uint)info.FanSpeed); } catch { return(0); } }
protected override void Build(IModel channal) { channal.QueueBind(queue: Queue, exchange: MqKeyword.NTMinerExchange, routingKey: MqKeyword.MinerSignSetedRoutingKey, arguments: null); channal.QueueBind(queue: Queue, exchange: MqKeyword.NTMinerExchange, routingKey: WsMqKeyword.GetConsoleOutLinesRoutingKey, arguments: null); channal.QueueBind(queue: Queue, exchange: MqKeyword.NTMinerExchange, routingKey: WsMqKeyword.FastGetConsoleOutLinesRoutingKey, arguments: null); channal.QueueBind(queue: Queue, exchange: MqKeyword.NTMinerExchange, routingKey: WsMqKeyword.ConsoleOutLinesRoutingKey, arguments: null); channal.QueueBind(queue: Queue, exchange: MqKeyword.NTMinerExchange, routingKey: WsMqKeyword.GetLocalMessagesRoutingKey, arguments: null); channal.QueueBind(queue: Queue, exchange: MqKeyword.NTMinerExchange, routingKey: WsMqKeyword.FastGetLocalMessagesRoutingKey, arguments: null); channal.QueueBind(queue: Queue, exchange: MqKeyword.NTMinerExchange, routingKey: WsMqKeyword.LocalMessagesRoutingKey, arguments: null); channal.QueueBind(queue: Queue, exchange: MqKeyword.NTMinerExchange, routingKey: WsMqKeyword.GetOperationResultsRoutingKey, arguments: null); channal.QueueBind(queue: Queue, exchange: MqKeyword.NTMinerExchange, routingKey: WsMqKeyword.FastGetOperationResultsRoutingKey, arguments: null); channal.QueueBind(queue: Queue, exchange: MqKeyword.NTMinerExchange, routingKey: WsMqKeyword.GetDrivesRoutingKey, arguments: null); channal.QueueBind(queue: Queue, exchange: MqKeyword.NTMinerExchange, routingKey: WsMqKeyword.DrivesRoutingKey, arguments: null); channal.QueueBind(queue: Queue, exchange: MqKeyword.NTMinerExchange, routingKey: WsMqKeyword.SetVirtualMemoryRoutingKey, arguments: null); channal.QueueBind(queue: Queue, exchange: MqKeyword.NTMinerExchange, routingKey: WsMqKeyword.GetLocalIpsRoutingKey, arguments: null); channal.QueueBind(queue: Queue, exchange: MqKeyword.NTMinerExchange, routingKey: WsMqKeyword.SetLocalIpsRoutingKey, arguments: null); channal.QueueBind(queue: Queue, exchange: MqKeyword.NTMinerExchange, routingKey: WsMqKeyword.LocalIpsRoutingKey, arguments: null); channal.QueueBind(queue: Queue, exchange: MqKeyword.NTMinerExchange, routingKey: WsMqKeyword.OperationResultsRoutingKey, arguments: null); channal.QueueBind(queue: Queue, exchange: MqKeyword.NTMinerExchange, routingKey: WsMqKeyword.OperationReceivedRoutingKey, arguments: null); channal.QueueBind(queue: Queue, exchange: MqKeyword.NTMinerExchange, routingKey: WsMqKeyword.GetSpeedRoutingKey, arguments: null); channal.QueueBind(queue: Queue, exchange: MqKeyword.NTMinerExchange, routingKey: WsMqKeyword.EnableRemoteDesktopRoutingKey, arguments: null); channal.QueueBind(queue: Queue, exchange: MqKeyword.NTMinerExchange, routingKey: WsMqKeyword.BlockWAURoutingKey, arguments: null); channal.QueueBind(queue: Queue, exchange: MqKeyword.NTMinerExchange, routingKey: WsMqKeyword.SwitchRadeonGpuRoutingKey, arguments: null); channal.QueueBind(queue: Queue, exchange: MqKeyword.NTMinerExchange, routingKey: WsMqKeyword.GetSelfWorkLocalJsonRoutingKey, arguments: null); channal.QueueBind(queue: Queue, exchange: MqKeyword.NTMinerExchange, routingKey: WsMqKeyword.SelfWorkLocalJsonRoutingKey, arguments: null); channal.QueueBind(queue: Queue, exchange: MqKeyword.NTMinerExchange, routingKey: WsMqKeyword.SaveSelfWorkLocalJsonRoutingKey, arguments: null); channal.QueueBind(queue: Queue, exchange: MqKeyword.NTMinerExchange, routingKey: WsMqKeyword.GetGpuProfilesJsonRoutingKey, arguments: null); channal.QueueBind(queue: Queue, exchange: MqKeyword.NTMinerExchange, routingKey: WsMqKeyword.GpuProfilesJsonRoutingKey, arguments: null); channal.QueueBind(queue: Queue, exchange: MqKeyword.NTMinerExchange, routingKey: WsMqKeyword.SaveGpuProfilesJsonRoutingKey, arguments: null); channal.QueueBind(queue: Queue, exchange: MqKeyword.NTMinerExchange, routingKey: WsMqKeyword.SetAutoBootStartRoutingKey, arguments: null); channal.QueueBind(queue: Queue, exchange: MqKeyword.NTMinerExchange, routingKey: WsMqKeyword.RestartWindowsRoutingKey, arguments: null); channal.QueueBind(queue: Queue, exchange: MqKeyword.NTMinerExchange, routingKey: WsMqKeyword.ShutdownWindowsRoutingKey, arguments: null); channal.QueueBind(queue: Queue, exchange: MqKeyword.NTMinerExchange, routingKey: WsMqKeyword.UpgradeNTMinerRoutingKey, arguments: null); channal.QueueBind(queue: Queue, exchange: MqKeyword.NTMinerExchange, routingKey: MqKeyword.StartMineRoutingKey, arguments: null); channal.QueueBind(queue: Queue, exchange: MqKeyword.NTMinerExchange, routingKey: MqKeyword.StartWorkMineRoutingKey, arguments: null); channal.QueueBind(queue: Queue, exchange: MqKeyword.NTMinerExchange, routingKey: WsMqKeyword.StopMineRoutingKey, arguments: null); NTMinerConsole.UserOk("OperationMq QueueBind成功"); }
public void MoveWindow(int marginLeft, int marginTop, int height) { if (!this.IsLoaded) { return; } const int paddingLeft = 4; const int paddingRight = 5; int width = (int)this.ActualWidth - paddingLeft - paddingRight - marginLeft; if (width < 0) { width = 0; } if (_marginLeft == marginLeft && _marginTop == marginTop && _height == height && _width == width) { return; } _marginLeft = marginLeft; _marginTop = marginTop; _height = height; _width = width; // 如果没有ConsoleBgRectangle的话鼠标会点击到桌面上 if (ConsoleBgRectangle.Width != width) { ConsoleBgRectangle.Width = width; } if (ConsoleBgRectangle.Height != height) { ConsoleBgRectangle.Height = height; } if ((int)ConsoleBgRectangle.Margin.Top != marginTop) { ConsoleBgRectangle.Margin = new Thickness(0, marginTop, 1, 0); } IntPtr console = NTMinerConsole.Show(); SafeNativeMethods.MoveWindow(console, paddingLeft + marginLeft, marginTop, width, height, true); }
public bool SetPowerLimit(int gpuIndex, int value) { if (!TryGetAtiGpu(gpuIndex, out ATIGPU gpu)) { return(false); } try { if (gpu.OverdriveVersion < 8) { ADLODNPowerLimitSetting info = new ADLODNPowerLimitSetting(); var r = AdlNativeMethods.ADL2_OverdriveN_PowerLimit_Get(_context, gpu.AdapterIndex, out info); if (r < AdlStatus.ADL_OK) { NTMinerConsole.DevError(() => $"{nameof(AdlNativeMethods.ADL2_OverdriveN_PowerLimit_Get)} {r.ToString()}"); return(false); } info.iMode = AdlConst.ODNControlType_Manual; info.iTDPLimit = value - 100; r = AdlNativeMethods.ADL2_OverdriveN_PowerLimit_Set(_context, gpu.AdapterIndex, ref info); if (r < AdlStatus.ADL_OK) { NTMinerConsole.DevError(() => $"{nameof(AdlNativeMethods.ADL2_OverdriveN_PowerLimit_Set)} {r.ToString()}"); return(false); } } else { if (GetOD8CurrentSetting(gpu.AdapterIndex, out ADLOD8CurrentSetting odCurrentSetting)) { SetOD8Range(gpu.ADLOD8InitSetting, odCurrentSetting, gpu.AdapterIndex, ADLOD8SettingId.OD8_POWER_PERCENTAGE, value == 0, value - 100); } } return(true); } catch (Exception e) { Logger.ErrorDebugLine(e); return(false); } }
private void SetCoreClock(int busId, int mHz, int voltage) { int kHz = mHz * 1000; try { if (NvGetPStateV2(busId, out NvGpuPerfPStates20InfoV2 info)) { info.numPStates = 1; info.numClocks = 1; info.pstates[0].clocks[0].domainId = NvGpuPublicClockId.NVAPI_GPU_PUBLIC_CLOCK_GRAPHICS; info.pstates[0].clocks[0].typeId = NvGpuPerfPState20ClockTypeId.NVAPI_GPU_PERF_PSTATE20_CLOCK_TYPE_SINGLE; info.pstates[0].clocks[0].freqDelta_kHz.value = kHz; var r = NvSetPStateV2(busId, ref info); if (!r) { NTMinerConsole.DevError(() => $"{nameof(SetCoreClock)} {r.ToString()}"); } } } catch { } }
public Task <List <SpeedData> > GetAllAsync() { var db = _redis.RedisConn.GetDatabase(); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); return(db.HashGetAllAsync(_redisKeySpeedDataByClientId).ContinueWith(t => { stopwatch.Stop(); long seconds = stopwatch.ElapsedMilliseconds / 1000; string text = $"{nameof(SpeedDataRedis)}的redis方法HashGetAllAsync耗时 {seconds.ToString()} 秒"; // 从redis一次性加载几十兆数据没有什么问题,打印些统计信息出来以待将来有问题时容易发现 if (seconds > 5) { NTMinerConsole.UserWarn(text); } else { NTMinerConsole.UserInfo(text); } stopwatch.Start(); List <SpeedData> list = new List <SpeedData>(); foreach (var item in t.Result) { if (item.Value.HasValue) { SpeedData data = VirtualRoot.JsonSerializer.Deserialize <SpeedData>(item.Value); if (data != null) { list.Add(data); } } } stopwatch.Stop(); seconds = stopwatch.ElapsedMilliseconds / 1000; NTMinerConsole.UserInfo($"反序列化和装配耗时 {seconds.ToString()} 秒"); return list; })); }
private void Init() { lock (_locker) { if (!_isInited) { // 将最近20分钟的快照载入内存 DateTime now = DateTime.Now; using (LiteDatabase db = CreateReportDb()) { var col = db.GetCollection <CoinSnapshotData>(); col.EnsureIndex(nameof(CoinSnapshotData.Timestamp), unique: false); foreach (var item in col.Find( Query.And( Query.GT(nameof(CoinSnapshotData.Timestamp), now.AddMinutes(-20)), Query.LTE(nameof(CoinSnapshotData.Timestamp), now)))) { _dataList.Add(item); } } NTMinerConsole.UserLine("将最近20分钟的快照载入内存", _isPull ? MessageType.Debug : MessageType.Info); _isInited = true; } } }
private uint GetPowerUsage(int gpuIndex) { if (!TryGetAtiGpu(gpuIndex, out ATIGPU gpu)) { return(0); } try { int power = 0; if (gpu.OverdriveVersion >= 6) { var r = AdlNativeMethods.ADL2_Overdrive6_CurrentPower_Get(_context, gpu.AdapterIndex, ADLODNCurrentPowerType.TOTAL_POWER, out power); if (r < AdlStatus.ADL_OK) { NTMinerConsole.DevError(() => $"{nameof(AdlNativeMethods.ADL2_Overdrive6_CurrentPower_Get)} {r.ToString()}"); return(0); } return((uint)(power / 256.0)); } } catch { } return(0); }
private static bool NvmlInit() { if (_isNvmlInited) { return(_isNvmlInited); } lock (_locker) { if (_isNvmlInited) { return(_isNvmlInited); } try { #if DEBUG NTStopwatch.Start(); #endif if (!File.Exists(_system32nvmlDllFileFullName) && File.Exists(_nvmlDllFileFullName)) { File.Copy(_nvmlDllFileFullName, _system32nvmlDllFileFullName); } var nvmlReturn = NvmlNativeMethods.NvmlInit(); _isNvmlInited = nvmlReturn == nvmlReturn.Success; #if DEBUG var elapsedMilliseconds = NTStopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { NTMinerConsole.DevTimeSpan($"耗时{elapsedMilliseconds} {nameof(NvmlHelper)}.{nameof(NvmlInit)}()"); } #endif return(_isNvmlInited); } catch (Exception e) { Logger.ErrorDebugLine(e); _isNvmlInited = true; } return(false); } }
private static bool NvFanCoolersGetControl(int busId, out PrivateFanCoolersControlV1 info) { info = PrivateFanCoolersControlV1.Create(); if (NvapiNativeMethods.NvFanCoolersGetControl == null) { return(false); } try { if (!HandlesByBusId.TryGetValue(busId, out NvPhysicalGpuHandle handle)) { return(false); } var r = NvapiNativeMethods.NvFanCoolersGetControl(handle, ref info); if (r != NvStatus.NVAPI_OK) { NTMinerConsole.DevError(() => $"{nameof(NvapiNativeMethods.NvFanCoolersGetControl)} {r.ToString()}"); return(false); } return(true); } catch { } return(false); }
private static bool NvPowerPoliciesGetInfo(int busId, out NvGpuPowerInfo info) { info = NvGpuPowerInfo.Create(); if (NvapiNativeMethods.NvPowerPoliciesGetInfo == null) { return(false); } try { if (!HandlesByBusId.TryGetValue(busId, out NvPhysicalGpuHandle handle)) { return(false); } var r = NvapiNativeMethods.NvPowerPoliciesGetInfo(handle, ref info); if (r != NvStatus.NVAPI_OK) { NTMinerConsole.DevError(() => $"{nameof(NvapiNativeMethods.NvPowerPoliciesGetInfo)} {r.ToString()}"); return(false); } return(true); } catch { return(false); } }
private void OverClock(INTMinerContext root, IGpuProfile data) { #if DEBUG NTStopwatch.Start(); #endif if (root.GpuSet.TryGetGpu(data.Index, out IGpu gpu)) { IOverClock overClock = root.GpuSet.OverClock; if (!data.IsAutoFanSpeed) { overClock.SetFanSpeed(data.Index, data.Cool); } overClock.SetCoreClock(data.Index, data.CoreClockDelta, data.CoreVoltage); overClock.SetMemoryClock(data.Index, data.MemoryClockDelta, data.MemoryVoltage); overClock.SetPowerLimit(data.Index, data.PowerCapacity); overClock.SetTempLimit(data.Index, data.TempLimit); if (data.Index == NTMinerContext.GpuAllId) { NTMinerConsole.UserOk($"统一超频:{data.ToOverClockString()}"); } else { NTMinerConsole.UserOk($"GPU{gpu.Index}超频:{data.ToOverClockString()}"); } 1.SecondsDelay().ContinueWith(t => { overClock.RefreshGpuState(data.Index); }); } #if DEBUG var elapsedMilliseconds = NTStopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { NTMinerConsole.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.OverClock"); } #endif }