I only have pain in bottom top of my penis when masturbating or having sex for a long period of time?

Tough to say. May be a strain of your penis. Try slowing down and possibly taking an nsaid. If it persists, get eval of the area. Best wishes.