Resolve overheating issue for AMD Radeon Graphics Card for GNOME 3.6 in Fedora 18


I have recently installed the Fedora 18 to my HP Envy 4 1002tx laptop which comes with AMD Radeon HD 7670M (2 GB DDR3 dedicated) with GNOME 3.6.2 and after logging in I was facing sever overheating issue and the laptop fan was making heavy noises. The overall battery backup was also getting reduced to some 1 hr 50 minutes.

The overheating was so sever that it was impossible to put my laptop on my lap as it was almost burning my legs.

I posted the issue on various forums and the full description can be found here: https://ask.fedoraproject.org/question/3811/fedora-18-severe-overheating-hp-envy-4-1002tx-in

I also tried installing the ATI radeon drivers using all the various methods like:

  • kmod-catalyst
  • akmod-catalyst
  • Official driver for linux from ATI site.

In all cases I ran into config issues because of which I was unable to boot into GNOME. These could only be resolved after deleting the Xorg.conf file.

After using all the 3 approaches above on rebooting I lost the gnome shell and my system will not bring up gnome. After deleting the xorg.conf I was able to get into gnome but was only presented with the downgraded version of gnome in which the system settings feature stopped working.

I like the gnome 3.6.2 interface and would want to stick to it that is why I am still running my laptop in Fedora irrespective of the overheating issue.

So after a little bit of searching I found out that the issue is because of GNOME interface which uses a lot of CPU power. [BUG for this https://bugzilla.redhat.com/show_bug.cgi?id=812624]

In the process I also got to know about the GNOME Shell Extensions where I found a plugin called Radeon Power Profile Manager . I installed it by enabling GNOME Shell in my browser and clicking on Toggling the ON-OFF switch next to the plugin name.

After installing the plugin I just checked if the power management in my machine is set to profile or not. This can be down by:

$ cat /sys/class/drm/card0/device/power_method
[\code]

After installing the plugin I could see it in my top-bar as an option where I clicked on it and choose the Set profile to “low” option.
Radeon Power Profile Manager Radeon Power Profile Manager
After using this plugin my CPU temperature came back to normal in 15 minutes. And now it it working at a very optimum temperature.

 

UPDATE: Better method:

The last method was good but somehow I was not seeing significant effects as the extension was crashing after I rebooted. So after a lot of searching I found a better method which has given me better results than the last solution.

All you need to do is run the following commands:

modprobe radeon
chown -R $USER:$USER /sys/kernel/debug
echo OFF > /sys/kernel/debug/vgaswitcheroo/switch

After this you can run sensors. I saw a drop in Physical id temperature from 72 C to 52 C which is quite good.

However the solution is only temporary and will be lost if you reboot. So you can put this script in rc.local and then it will be applied each time you boot into your machine.

Edit your /etc/rc.d/rc.local with the following commands:

#!/usr/bin/env sh

modprobe radeon
echo OFF > /sys/kernel/debug/vgaswitcheroo/switch

And then enable it by running the following commands:

systemctl enable rc-local.service
systemctl start rc-local.service
systemctl status rc-local.service # Check the status if its running or not.

The solution is taken from: http://zhegu.wordpress.com/2013/01/11/fedora-linux-overheat-problem-on-sony-vaio/

So after days of searching I finally found the solution. Thanks to Stunts for making this plugin available. The full documentation for the plugin can be found at: 

Python code to calculate the largest prime factor of a large number – Project Euler


I have started using Project Euler recently for fun, and today I was able to solve problem 3 through great help from my friend Sangam.

The problem talks about finding the largest prime factor of a large number. [http://projecteuler.net/problem=3]

ProjectEuler.net
ProjectEuler.net

The solution to the problem might look very trivial through the use of brute force and iterating over all the possible factors of the number and checking if they are prime. However, for very large numbers [if more than 10 digits] this process will fail as the computation will be too long.

To tackle this problem my friend came up with a very intuitive solution which reduces the number of calculations for finding prime and uses few fundamental concepts to reach the solution faster and more efficiently. The assumptions are as follows:

For a given number {n=2^{\alpha}3^{\beta}5^{\gamma}...p^{\kappa}}

  1. Check if the number is divisible by 2, 3 or 5
  2. If it is then strip all the powers of 2, 3, and 5 we are left with all powers of 7, 11, 13 … 29 ….
  3. Now since the LCM of 2, 3, 5 is 30 hence we map all the primes less than 30 excluding 2, 3, 5 and including 1 to all the number greater than 30 as 30+prime_before at same index in the list.
  4. We continue the process of splitting all the powers of the primes which divide the number till we reach a point where only the powers of p are remaining.
  5. Once we split all but one powers of p we are left with n = p which gives us p as the largest prime factor.

The original raw code for this algorithm as written by Sangam can be found at: https://github.com/napsternxg/Project-Euler/blob/master/test.py

The final code after modification and making if modular and efficient is presented below:


"""
The original code for the following program was written by Sangam Kumar Jain and can be found in the file test.py in this git project
You can connect with him at: http://www.facebook.com/jain.sangam
The code was written as a part of solving Project Euler Problem 3 (http://projecteuler.net/problem=3) which deals with finding the largest prime factor of a large number.
Currently the code finds all the powers of all prime factors of any large number.
I have rewritten a more modular and optimized version of the above code and tried to make it more easily comprehendable.
"""
import sys;
import datetime;
# Profiling started, string to write to log file
print "#"*60
print "Profiling started for: ", sys.argv;
print "Start time: ", str(datetime.datetime.now()), "\n\n";
def nextprime(loop, current_index, prime_list):
# Function to return the next prime to check for and also to populate the list array with numbers mapping to the current list items for the next 30 numbers.
if(current_index == 7):
loop = loop+1;
current_index = 0;
else:
current_index = current_index +1
return (loop * 30 + prime_list[current_index], loop, current_index, prime_list)
def checkDivisibility(number, val):
# Strip all powers of subsequent primes from the number till the number equal to the prime which divides it
i = 1;
factors = []
while(number%val == 0):
#print number, val**i;
factors.append(val**i);
number = number / val; # Reduce the number by factor of val
i = i + 1;
return (number, factors)
def updateFactors(factors, factor):
# Function to update the factors of the number with the factors found using checkDivisibility
if factor != [] :
# Append factor only if it is non empty
factors.append(factor);
return factors
def findFactors(number):
# Function to find all the factors of the number and to also print the largest factor of the number
val = 7;
loop = 0;
current_index = 1;
prime_list = [1,7,11,13,17,19,23,29]; # List to populate with all primes less than 30
factors = []; # Store all prime powers of a number
# Strip all powers of 2 from the number
number, factor = checkDivisibility(number, 2);
factors = updateFactors(factors, factor);
# Strip all powers of 3 from the number
number, factor = checkDivisibility(number, 3);
factors = updateFactors(factors, factor);
# Strip all powers of 5 from the number
number, factor = checkDivisibility(number, 5);
factors = updateFactors(factors, factor);
# Strip all powers of subsequent primes from the number till the number equal to the prime which divides it
while(number/val != 0):
number, factor = checkDivisibility(number, val);
factors = updateFactors(factors, factor);
#Get Next Prime to check for and simultaneously update loop, current_index and prime_list
val, loop, current_index, prime_list = nextprime(loop, current_index, prime_list)
#Append the last factor in the factor list
#factors.append([val])
#print "Largest Prime:", factors[-1][0]
return factors;
def findLargestPrimeFactor(number):
return findFactors(number)[-1][0];
#Run the code for number given below and print the largest factor along with the set of powers of prime factors
#number = 18505779463480206643200; # Number to factorize
number = long(sys.argv[1]);
factors = findFactors(number)
print "All powers of prime factors of ", number, " are as follows:\n", factors, "\n\nAnd the largest prime factor is:", factors[-1][0];
#Finish Profiling Printing
print "\n\nEnd time: ", str(datetime.datetime.now());
print "Profiling finished for: ", sys.argv;
print "#"*60

The code runs very fast and for a number: 18505779463480206643200 it executes 702 function calls in 0.001 seconds. The detailed results of the profiler can be found at: https://github.com/napsternxg/Project-Euler/blob/master/profile_log.txt

For the above number the profile gave the following output:

############################################################
Profiling started for: [‘largestPrimeFactor.py’, ‘18505779463480206643200’]
Start time: 2012-09-24 03:04:56.384000
All powers of prime factors of 18505779463480206643200 are as follows:
Largest Prime: 823
[[2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096], [3, 9, 27, 81, 243, 729], [5, 25], [7, 49, 343, 2401], [13], [61], [281], [563], [823]]
End time: 2012-09-24 03:04:56.384000
Profiling finished for: [‘largestPrimeFactor.py’, ‘18505779463480206643200’]
############################################################
         702 function calls in 0.001 seconds
   Ordered by: standard name
   ncalls tottime percall cumtime percall filename:lineno(function)
        1 0.000 0.000 0.001 0.001 largestPrimeFactor.py:11(<module>)
      218 0.000 0.000 0.000 0.000 largestPrimeFactor.py:20(nextprime)
      221 0.000 0.000 0.000 0.000 largestPrimeFactor.py:29(checkDivisibility)
      221 0.000 0.000 0.000 0.000 largestPrimeFactor.py:43(updateFactors)
        1 0.000 0.000 0.000 0.000 largestPrimeFactor.py:51(findFactors)
        2 0.000 0.000 0.000 0.000 {built-in method now}
       37 0.000 0.000 0.000 0.000 {method ‘append’ of ‘list’ objects}
        1 0.000 0.000 0.000 0.000 {method ‘disable’ of ‘_lsprof.Profiler’ objects}
If you have suggestions on improving this algorithm or queries regarding its accuracy do write to me in the comment section. Also you can connect with Sangam at: http://www.facebook.com/jain.sangam
My Project Euler repository can be forked from github at: https://github.com/napsternxg/Project-Euler
Happy Coding =)

Fetch Tweets Using jQuery & JSON: TweeteReads


Update: The App right now works best in Mozilla Firefox 7.0+ also sometimes you will get no tweets when using Chrome or other browser. This is not an error but a restriction by twitter on the no of API calls a particular application can make and hence restricted by twitter.

Twitter is growing popular day by day and has already occupied a place in users browsers & smartphones as Apps. The power of the social media apps and other web applications these days is that they allow users to use the app without even the need for visiting the webpage of that app.

I recently had the opportunity to solve the following problem:

Write an HTML page to fetch the top 10 tweets of a user whose Screen Name is entered by the user.

Looks trivial, considering the RSS feed of a twitter user are easily available. You can check the RSS Feed of my tweets at https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=theshubhanshu&count=2

However when writing an HTML page this method of retrieving tweets via RSS won’t work because of the security issues of HTML. The reason is your HTML page will try to do a Cross Site Request [XSS Request] which is not allowed by browsers.

To solve this problem, the web architect community came up with a new format of information exchange between 2 websites called JSON [JavaScript Object Notation] which allows websites to develop APIs to allow other web applications to use their data.

Twitter Supports JSON as one of the formats for data exchange in its API. https://dev.twitter.com/docs/api

To solve the problem stated above. I used Twitter’s JSON API to fetch the latest tweets of any user whose screen_name is given. I used jQuery to publish the tweets on the web page.

function getTweets(){
$("#tweets").html("</pre>
<h1>Loading ...</h1>
<pre>
");
var screen_name = document.getElementsByName("screen_name")[0].value;
$.getJSON("https://api.twitter.com/1/statuses/user_timeline.json?screen_name="+screen_name+"&count=10&callback=?",
 function(data) {
 $("#tweets").html("");
 $.each(data, function(i,item){
 $("

").html(item.text).appendTo("#tweets");
 if ( i == 10 ) return false;
 });
 });
}

The code above uses the jQuery getJSON function to fetch and parse the tweets in JSON format and display them on the webpage.

I used the GET statuses/friends_timeline function of the twitter api.

I added a little bit of styling to the page which rendered the page like this:

TweeteReads
TweeteReads

The full code of the page is

<!DOCTYPE html>
<html>
<head>
  <style>img{ height: 100px; float: left; }</style>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
  <style>
  *{
	margin: 0px;
  }
  body{
	font: 20px cursive;
	margin: 0px;
  }
  #header{
  margin: 0px;
	background-color: #9AE4E8;
	border-bottom: solid 2px black;
  }
  p{
	background-color: #9AE4E8;
	padding: 2px;
	margin: 10px auto;
	border: solid 1px black;
	width: 50%;
  }
  #tweets{
	text-align: center;
  }
  input{
	
    border: 5px solid #9AE4E8;
    border-radius: 5px 5px 5px 5px;
    font: 20px cursive;
	margin: auto;
  }
  input[type="text"]{
	text-align: right;
	width: 50%; 
	
  }
  input[type="submit"]{
	background-color: #4DB8FF;
  }
  #inputPanel{
	margin: 50px auto;
	text-align: center;
  }
  </style>
</head>
<body>
<div id="header">
<h1 align="center">TweeteReads</h1>
<h4 align="center">Designed & Coded by <a href="http://twitter.com/theshubhanshu">@TheShubhanshu</a></h4>
</div>
<div id="inputPanel">
<input type="text" name="screen_name" />
<input type="submit" value="Retrieve Tweets" onclick="javascript: getTweets();" />
</div>

<div id="tweets">

</div>

<script>
function getTweets(){
$("#tweets").html("<h1>Loading ...</h1>");
var screen_name = document.getElementsByName("screen_name")[0].value;
$.getJSON("https://api.twitter.com/1/statuses/user_timeline.json?screen_name="+screen_name+"&count=10&callback=?",
  function(data) {
	$("#tweets").html("");
    $.each(data, function(i,item){
      $("<p />").html(item.text).appendTo("#tweets");
      if ( i == 10 ) return false;
    });
  });
}
</script>

</body>
</html>
The full source code can be downloaded from : https://sites.google.com/site/shubhanshumishra/jsonTest.htm
Please feel free to post a comment if you find any difficulty in using the app.
Feel free to share the information and help others.

Reject ALL Requests with 1 Click


Hi everyone, thanks for visiting my last article on Confirm ALL Friend Requests with 1 Click I received a lot of feedback regarding that on twitter. A lot of them asking to also give a code for REJECTing all the requests on Facebook with 1 click.

Thanks Saptak for the idea. Here you are =)

So when you get a lot of friend requests and find it boring to click Not Now on each one of them. Then just create this bookmarklet and use it to REJECT all friend requests with just 1 click. Simple!

Important point: this bookmarklet will reject all the requests on the page including event invites, apps, etc.

I have already given a tutorial on how to make a bookmarklet in your browser. So if you are a newbie to makeing a bookmarklet read How to Invite all Friends Facebook Event

In the above Bookmarklet just change the URL to the following code to get your bookmarklet for confirming all friend requests.

javascript: var field = document.getElementsByName("actions[hide]");for (i = 0; i &lt; field.length; i++)field[i].click() ;
Reject Requests but do confirm the one's you do want to add
Reject Requests but do confirm the one's you do want to add

Now once created. Go to the following page to get all your Friend Requests: http://www.facebook.com/reqs.php and use the bookmarklet to reject all your requests which you do not want. [Don’t forget to accept the ones you do want manually before clicking the bookmarklet].

PS: Its unsafe to accept unknown friend requests on facebook as a lot of your private information which you wish only your close friends should know becomes accessible to all your facebook friends. This includes messages, contacts, personal pictures etc.

Please feel free to post a comment if you find any difficulty in using the bookmarklet.
Also Read about how to make the bookmarklet which Confirm ALL Friend Requests with 1 Click
Feel free to share the information and help others.

Confirm ALL Friend Requests with 1 Click


Facebook is growing and so is the about of connections we are making. It happens a lot of time that when people join facebook that they get a lot of friend requests. Its highly suggested that you make friends with only the people you know.

So when you get a lot of friend requests and find it boring to click confirm on each one of them. Then just create this bookmarklet and use it to confirm all friend requests with just 1 click. Simple!

I have already given a tutorial on how to make a bookmarklet in your browser. So if you are a newbie to makeing a bookmarklet read How to Invite all Friends Facebook Event

Join Zipcar and get $25 in free driving

In the above Bookmarklet just change the URL to the following code to get your bookmarklet for confirming all friend requests.

javascript: var field = document.getElementsByName("actions[accept]");for (i = 0; i < field.length; i++)field[i].click() ;
Confirm Requests
Confirm Requests but do Reject the one’s you don’t want to add

Now once created. Go to the following page to get all your Friend Requests: http://www.facebook.com/reqs.php and use the bookmarklet to confirm all your new friend requests. [Don’t forget to reject the ones you don’t want manually before clicking the bookmarklet].

PS: Its unsafe to accept unknown friend requests on facebook as a lot of your private information which you wish only your close friends should know becomes accessible to all your facebook friends. This includes messages, contacts, personal pictures etc.

Join Zipcar and get $25 in free driving

Please feel free to post a comment if you find any difficulty in using the bookmarklet.
Feel free to share the information and help others.

Join Zipcar and get $25 in free driving