By my previous article of "How to control the CPU occupation rate", someone came up with another idea - "How to get or compute the CPU frequency when I run the program in different PCs?"
That's really a challenge! But it's not a big problem by the same theory of CPU occupation control. We know now that CPU can run about 2 directives per tick, and the frequency is the count of ticks per second, and each for(i=0;i<n;i++) cycle contains about more than 5 ASM directives. By these estimated parameters, we will be able to compute the CPU frequency via a reverse computation engineering.
The source code is showed as below:
/* GetCPUFrequency.java
*
* TSUSOFT.NET, ALEXELA.CN
* Copyright (C) 2007 by Alexandre Tsu
*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the License.
*
* Alternatively, the contents of this file may be used under the terms of the
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
* provisions of LGPL are applicable instead of those above. If you wish to
* allow use of your version of this file only under the terms of the LGPL
* License and not to allow others to use your version of this file under
* the MPL, indicate your decision by deleting the provisions above and
* replace them with the notice and other provisions required by the LGPL.
* If you do not delete the provisions above, a recipient may use your version
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
*
* Created on Aug 21, 2007, by Alexandre Tsu.
*
*/
public class GetCPUFrequency
{
public static void main(String[] args)
{
try
{
if(args.length != 2)
printUsage();
/* parameters estimation from input */
float dpt = Float.parseFloat(args[0]);
float dpc = Float.parseFloat(args[1]);
System.out.print("Hit <Enter> to go on!");
System.in.read();
/* run cycles for Integer.MAX_VALUE times */
long l1 = System.currentTimeMillis();
for(int i=0; i<Integer.MAX_VALUE; i++);
long l2 = System.currentTimeMillis();
/* compute the cycles per second */
long cps = Integer.MAX_VALUE / ( (l2 - l1) / 1000 );
/* output the computation result */
System.out.println("Directives per tick: " + dpt);
System.out.println("Directives per cycle: " + dpc);
System.out.println("Cycles per second: " + cps);
System.out.println("CPU Frequency at: " + (cps * dpc / dpt));
}
catch(Throwable e)
{
printUsage();
}
}
private static void printUsage()
{
System.out.println("Usage: java GetCPUFrequency dpt dpc");
System.out.println("dpt: directives per tick");
System.out.println("dpc: directives per cycle");
System.exit(1);
}
}
I tried running this program in different PCs (one with Windows and anther with Linux). I got a close result to my real CPU frequency. For my pratice, I estimated the two input parameters as 2 and 15. My actual CPU frequency is 1.40Ghz. One of run situation is as below:
D:\workspace\Test>java GetCPUFrequency 2 15
Hit <Enter> to go on!
Directives per tick: 2.0
Directives per cycle: 15.0
Cycles per second: 195225786
CPU Frequency at: 1.46419341E9
分享到:
相关推荐
总的来说,`COMPUTE`和`COMPUTE BY`是用于对查询结果进行分组聚合的老式语法,它们在现代SQL中可能被更现代的`GROUP BY`和`OVER`子句替代,但理解这些概念对于理解数据库的历史和一些旧系统的查询结构仍然很重要。
描述:R5版本FusionCompute JAVA API接口,提供随需使用的虚拟化计算能力,以及为支撑计算能力而必须配套的存储及网络能力。 1.文档放在doc中,包含开发指南和接口参考。 2.程序放在software中,提供形态为Java ...
描述:iOS版本eSpace控件接口,提供IM、呼叫、会议、联系人及群组等相关能力。 1.文档放在doc中,包含控件使用指南。 2.程序放在software中,当前提供iPhone版本控件程序包。 3.编程代码样例放在demo中,包含demo...
《eSDK Cloud V100R005C10 代码样例 01(FusionCompute, R5, REST, Java)》是华为提供的一个针对FusionCompute R5版本的开发工具包,旨在帮助开发者利用Java语言进行云计算平台的集成与应用开发。在这个资源包中,...
DirectCompute draws a sharp distinction between the code that runs on the host (typical C or C++) and the code that runs on the device (C-like HLSL kernel code). The host code and the device code ...
《eSDK Cloud V100R005C10 代码样例 01:基于FusionCompute R3的RESTful API与Java编程实践》 eSDK Cloud是一款由华为提供的云服务开发套件,其V100R005C10版本主要针对FusionCompute R3接口,提供了丰富的代码示例...
在安装CNA前,你需要确保服务器硬件配置符合要求,包括但不限于CPU支持虚拟化功能,内存至少8GB。对于VRM节点,由于其承担了数据中心的管理任务,因此建议配置更高,例如硬盘需组RAID 10以提供高可用性,至少2个磁盘...
Compute the transforn function H(2) of this system.pdf
计算着色器(Compute Shader,CS)是DirectX 11引入的一个新概念,它扩展了GPU的功能,使其能够处理通用计算任务,比如物理模拟、图像处理、矩阵运算等。CS使用 HLSL(High-Level Shading Language)编写,与像素...
C#加密转换为Java的加密 在本篇资源中,我们将讨论C#的加密转换为Java的加密,特别是MD5加密的实现。在C#中,我们使用MD5CryptoServiceProvider类来实现MD5加密,而在Java中,我们使用MessageDigest类来实现MD5加密...
在Android平台上,使用Compute Shader可以显著提升计算密集型任务的执行效率,特别是在图形处理和物理模拟等场景。Compute Shader是OpenGL ES 3.0引入的一个重要特性,它允许开发者利用GPU进行并行计算,不再局限于...
4. 使用`COMPUTE BY`必须配合`ORDER BY`,并且`ORDER BY`的列顺序和`COMPUTE BY`中的一致,且`COMPUTE BY`中的列必须是`ORDER BY`列表的全部或连续部分。 5. 如果省略了`BY`,那么`ORDER BY`也可以省略,此时`...
Design and write a Java class named SalesArray.java that will: 1. Declare a two-dimensional integer array named sales. Populate the first four columns using the following data. Quarter 1 Quarter 2 ...
《华为FusionCompute配置详解》 华为FusionCompute是一款企业级的云计算管理平台,它能够实现虚拟化资源的高效管理和调度。本配置笔记主要涵盖了FusionCompute中的几个关键配置环节,包括主机HBA卡的WWN号查看、...
在IT行业中,"esb java compute节点连接oracle做CURD"是指使用Enterprise Service Bus (ESB)中的Java Compute节点来实现对Oracle数据库的Create, Read, Update, Delete(CRUD)操作。本文将详细介绍这个过程,包括...
《FusionCompute_Installer-8.0.0.zip:深入了解华为FusionCompute虚拟化平台》 华为FusionCompute是一款强大的企业级虚拟化平台,旨在提供高效、可靠的云计算基础设施服务。在给定的压缩包文件“FusionCompute_...
文本文件内附百度网盘连接及提取码。 以及详细资源列表,方便学习使用。...本资源适合搭建FusionCompute实验环境。 资源包含几乎全部FusionCompute8.0组件。 资源绝对真实,童叟无欺,如若妄言,天打雷劈!
Run the example by going to c:\java\lab7 and typing: java ynu/edu/lab7/UseCourse For example, the output could be: The cost of your course is $180.0 there is a $25.00 lab fee. The cost of your ...
### 华为FusionCompute安装知识点详述 #### 一、FusionCompute概览 **华为FusionCompute**是一款企业级虚拟化平台解决方案,旨在帮助组织实现服务器虚拟化和云计算环境的构建。它通过集中管理和优化计算资源,提高...
《FusionCompute 6.5.1 接口详解与应用》 FusionCompute作为一款先进的虚拟化平台,其6.5.1版本在接口功能上有着丰富的拓展性,为IT管理员提供了强大的管理与监控能力。本文将深入探讨FusionCompute 6.5.1的SNMP...